add solar_panels and calculate energy gen/use
[browser-rts.git] / src / lib / util.ts
index ebe84e5a4fac8d734d211d64f4034c7df27146fe..03aed1557bdc804fb2034529067b87f007eb87a8 100644 (file)
@@ -1,9 +1,20 @@
-export function coalesce(...args: any[]): any {
+import { isEmpty } from 'lodash';
+
+export function coalesce(...args) {
     let found;
     while(args.length) {
         found = args.shift();
-        if(found !== null && found !== undefined && found !== '') {
+        if(found !== null && found !== undefined && !isEmpty(found)) {
             return found;
         }
     }
-}
\ No newline at end of file
+}
+
+export function pluck<T>(arr: T[], field: string): Map<string, T> {
+  const map = new Map<string, T>();
+  arr.forEach(obj => {
+    map[obj[field]] = obj;
+  });
+
+  return map;
+}