Commit | Line | Data |
---|---|---|
41534b92 BA |
1 | export const ArrayFun = { |
2 | ||
3 | // Double array intialization | |
4 | init: function(size1, size2, initElem) { | |
5 | return [...Array(size1)].map(() => Array(size2).fill(initElem)); | |
6 | }, | |
7 | ||
8 | range: function(max) { | |
9 | return [...Array(max).keys()]; | |
15106e82 BA |
10 | }, |
11 | ||
12 | toObject: function(keys, values) { | |
13 | if (!Array.isArray(values)) | |
14 | // Second argument is a scalar | |
15 | values = Array(keys.length).fill(values); | |
16 | return ( | |
17 | ArrayFun.range(keys.length) | |
18 | .reduce((acc, curr) => (acc[keys[curr]] = values[curr], acc), {}) | |
19 | ); | |
41534b92 BA |
20 | } |
21 | ||
22 | }; |