X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2Farray.js;h=3d7f7ae4260c1852b6d8691082ce637813402c63;hb=HEAD;hp=4d44db02d324512a786ecea6eb5e4b875eebb836;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;p=vchess.git diff --git a/client/src/utils/array.js b/client/src/utils/array.js index 4d44db02..3d7f7ae4 100644 --- a/client/src/utils/array.js +++ b/client/src/utils/array.js @@ -1,10 +1,11 @@ // Remove item(s) in array (if present) export const ArrayFun = { + remove: function(arr, rfun, all) { const index = arr.findIndex(rfun); if (index >= 0) { arr.splice(index, 1); - if (all) { + if (!!all) { // Reverse loop because of the splice below for (let i = arr.length - 1; i >= index; i--) { if (rfun(arr[i])) arr.splice(i, 1); @@ -21,4 +22,5 @@ export const ArrayFun = { range: function(max) { return [...Array(max).keys()]; } + };