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