[solved] Drop It Challenge Issue

Is the “Drop It” challenge broken? Either that or I don’t understand the problem, because the expected answers for:


dropElements([0, 1, 0, 1], function(n) {return n === 1;})

and

dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})

don’t make sense.

1 Like
dropElements([0, 1, 0, 1], function(n) {return n === 1;})

n === 1 becomes true on the second element, so only the first element is removed and we get [1, 0, 1]


dropElements([1, 2, 3, 9, 2], function(n) {return n > 2;})

n > 2 on the third element, so the first two elements are removed and we get [3, 9, 2]

2 Likes

Oh, so the function is meant to stop working after it’s proven true?

Yes - you stop checking the array on the 1st eval to true. My solution used .indexOf() for that very reason (finds the 1st instance in a collection).

1 Like

Correct. The key word in the instructions is “until”.

Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.

1 Like

With that in mind it’s pretty straight forward. Thanks everyone.