Some more refactoring - not working for now
[xogo.git] / utils / array.js
index 8f2ebfe..c2cb25f 100644 (file)
@@ -7,6 +7,16 @@ export const ArrayFun = {
 
   range: function(max) {
     return [...Array(max).keys()];
+  },
+
+  toObject: function(keys, values) {
+    if (!Array.isArray(values))
+      // Second argument is a scalar
+      values = Array(keys.length).fill(values);
+    return (
+      ArrayFun.range(keys.length)
+      .reduce((acc, curr) => (acc[keys[curr]] = values[curr], acc), {})
+    );
   }
 
 };