X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Futils%2Farray.js;h=1b92e3507045e3fda9168ead36af7487ccb04751;hp=b438eaae697cd8ce049b6e3a6deeed450df6d13c;hb=e27329232b83700d63c8fb52af6f4c2eec9a569c;hpb=c75838d9d5b52d1fbd3e419c5073ef0cfb95f40a diff --git a/client/src/utils/array.js b/client/src/utils/array.js index b438eaae..1b92e350 100644 --- a/client/src/utils/array.js +++ b/client/src/utils/array.js @@ -1,29 +1,32 @@ // Remove item(s) in array (if present) -export function remove(array, rfun, all) +export const ArrayFun = { - const index = array.findIndex(rfun); - if (index >= 0) + remove: function(array, rfun, all) { - array.splice(index, 1); - if (!!all) + const index = array.findIndex(rfun); + if (index >= 0) { - // Reverse loop because of the splice below - for (let i=array.length-1; i>=index; i--) + array.splice(index, 1); + if (!!all) { - if (rfun(array[i])) - array.splice(i, 1); + // Reverse loop because of the splice below + for (let i=array.length-1; i>=index; i--) + { + if (rfun(array[i])) + array.splice(i, 1); + } } } - } -} + }, -// Double array intialization -export function init(size1, size2, initElem) -{ - return [...Array(size1)].map(e => Array(size2).fill(initElem)); -} + // Double array intialization + init: function(size1, size2, initElem) + { + return [...Array(size1)].map(e => Array(size2).fill(initElem)); + }, -export function range(max) -{ - return [...Array(max).keys()]; -} + range: function(max) + { + return [...Array(max).keys()]; + }, +};