The partitionOn function takes 2 arguments, pred is a function that specifies the conditions for selecting elements from the items array.
The function must return the length of the new array with elements satisfying pred . And also change the array of items , which takes as an argument.
In my code, items does not change in the outer scope. How to make it change?
I am writing in the console
window.items.concat(arrPredFalse, arrPredTrue); and it works, but codewars gives an error.
function partitionOn(pred, items) { var arrPredTrue = []; var arrPredFalse = []; for (var i = 0; i < items.length; i++) { if (pred(items[i])) { arrPredTrue.push(items[i]); } else { arrPredFalse.push(items[i]); } } items.concat(arrPredFalse, arrPredTrue); return arrPredTrue.length; }
concat, which returns a new array,splicewhich changes the array to which it is applied - Grundy