Tell us what’s happening:
I came up with a solution and it passes the challenge, at least the test cases that are required to pass. But the initial arguments proposed in the challenge
dropElements([1, 2, 3], function(n) {return n < 3; }
does not pass.
Your code so far
function dropElements(arr, func) {
let newArr = [];
for (let i = 0; i < arr.length; i++) {
if (func(arr[i])) {
newArr = arr.slice(i);
break;
}
}
return newArr;
}
dropElements([1, 2, 3], function(n) {return n < 3; });
I understand that the problem is that the for
loop breaks as soon as the function condition is satisfied (n < 3).
arr[0]
is 1 and the condition is immediately satisfied.
I noticed that all of the test case conditions use ‘greater than’, ‘greater than or equal to’ or ‘strictly equal’. None of the test cases use ‘less than or equal to’.
I know it passes the challenge, but the fact that the default arguments did not pass is really bugging me.
I am very new to coding and I was wondering if there is a way to identify the index of the slice position, regardless of whether the comparison operator is ‘less than’ or ‘greater than’.
I’m not looking to be spoon fed. Any hints or suggestions would be appreciated.