Attempt to clarify installation instructions a little
[vchess.git] / client / src / utils / array.js
... / ...
CommitLineData
1// Remove item(s) in array (if present)
2export const ArrayFun = {
3
4 remove: function(arr, rfun, all) {
5 const index = arr.findIndex(rfun);
6 if (index >= 0) {
7 arr.splice(index, 1);
8 if (!!all) {
9 // Reverse loop because of the splice below
10 for (let i = arr.length - 1; i >= index; i--) {
11 if (rfun(arr[i])) arr.splice(i, 1);
12 }
13 }
14 }
15 },
16
17 // Double array intialization
18 init: function(size1, size2, initElem) {
19 return [...Array(size1)].map(() => Array(size2).fill(initElem));
20 },
21
22 range: function(max) {
23 return [...Array(max).keys()];
24 }
25
26};