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