Fix Dobutsu
[xogo.git] / utils / array.js
CommitLineData
41534b92
BA
1export const ArrayFun = {
2
3 // Double array intialization
4 init: function(size1, size2, initElem) {
5 return [...Array(size1)].map(() => Array(size2).fill(initElem));
6 },
7
3232aba3
BA
8 range: function(min, max) {
9 if (!max) {
10 max = min;
11 min = 0;
12 }
13 return [...Array(max - min).keys()].map(k => k + min);
15106e82
BA
14 },
15
16 toObject: function(keys, values) {
17 if (!Array.isArray(values))
18 // Second argument is a scalar
19 values = Array(keys.length).fill(values);
20 return (
21 ArrayFun.range(keys.length)
22 .reduce((acc, curr) => (acc[keys[curr]] = values[curr], acc), {})
23 );
41534b92
BA
24 }
25
26};