1 export const ArrayFun
= {
3 // Double array intialization
4 init: function(size1
, size2
, initElem
) {
5 return [...Array(size1
)].map(() => Array(size2
).fill(initElem
));
8 range: function(min
, max
) {
13 return [...Array(max
- min
).keys()].map(k
=> k
+ min
);
16 toObject: function(keys
, values
) {
17 if (!Array
.isArray(values
))
18 // Second argument is a scalar
19 values
= Array(keys
.length
).fill(values
);
21 ArrayFun
.range(keys
.length
)
22 .reduce((acc
, curr
) => (acc
[keys
[curr
]] = values
[curr
], acc
), {})