Tell us what’s happening:
Hey guys, I want to know why my code doesn’t work if I change line 3 to
let newArr = arr;
(Please refer to line 3)
Your code so far
function dropElements(arr, func) {
// Drop them elements.
let newArr = [...arr]; // The code doesn't work if I change this to let newArr = arr
for (let i = 0; i < arr.length; i++) {
if (!func(arr[i])) {
newArr.shift();
} else {
break;
}
}
return newArr;
}
dropElements([1, 2, 3], function(n) {return n < 3; });
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge: