Commit | Line | Data |
---|---|---|
8d61fc4a | 1 | // Remove item(s) in array (if present) |
e2732923 | 2 | export const ArrayFun = |
8d61fc4a | 3 | { |
9d58ef95 | 4 | remove: function(arr, rfun, all) |
8d61fc4a | 5 | { |
9d58ef95 | 6 | const index = arr.findIndex(rfun); |
e2732923 | 7 | if (index >= 0) |
8d61fc4a | 8 | { |
9d58ef95 | 9 | arr.splice(index, 1); |
e2732923 | 10 | if (!!all) |
8d61fc4a | 11 | { |
e2732923 | 12 | // Reverse loop because of the splice below |
9d58ef95 | 13 | for (let i=arr.length-1; i>=index; i--) |
e2732923 | 14 | { |
9d58ef95 BA |
15 | if (rfun(arr[i])) |
16 | arr.splice(i, 1); | |
e2732923 | 17 | } |
8d61fc4a BA |
18 | } |
19 | } | |
e2732923 | 20 | }, |
8d61fc4a | 21 | |
e2732923 BA |
22 | // Double array intialization |
23 | init: function(size1, size2, initElem) | |
24 | { | |
25 | return [...Array(size1)].map(e => Array(size2).fill(initElem)); | |
26 | }, | |
c66a829b | 27 | |
e2732923 BA |
28 | range: function(max) |
29 | { | |
30 | return [...Array(max).keys()]; | |
31 | }, | |
32 | }; |