Commit | Line | Data |
---|---|---|
8d61fc4a | 1 | // Remove item(s) in array (if present) |
e2732923 | 2 | export const ArrayFun = |
8d61fc4a | 3 | { |
e2732923 | 4 | remove: function(array, rfun, all) |
8d61fc4a | 5 | { |
e2732923 BA |
6 | const index = array.findIndex(rfun); |
7 | if (index >= 0) | |
8d61fc4a | 8 | { |
e2732923 BA |
9 | array.splice(index, 1); |
10 | if (!!all) | |
8d61fc4a | 11 | { |
e2732923 BA |
12 | // Reverse loop because of the splice below |
13 | for (let i=array.length-1; i>=index; i--) | |
14 | { | |
15 | if (rfun(array[i])) | |
16 | array.splice(i, 1); | |
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 | }; |