Intermediate Algorithm Scripting - Drop it

Tell us what’s happening:
Can anyone tell me why my code is wrong?

I really dont get why and how

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

should return [1, 0, 1] ? How can 0 be strictly equal to 1?

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

how can it return [3, 9, 2] ? 2 is not greater than 2 :confused:

Your code so far

function dropElements(arr, func) {
  const filteredElems = [];

  for (let i = 0; i < arr.length; i++) {
    const currentItem = arr[i];
    if (func(currentItem)) filteredElems.push(currentItem);
  }

  return filteredElems;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36

Challenge: Intermediate Algorithm Scripting - Drop it

Link to the challenge:

Take another look at the instructions:

Then return the rest of the array once the condition is satisfied

The challenge expects you to iterate through the array, find the first element that returns true when passed to func, then return all elements after and including that first truthy element.

1 Like

Ah thankyou for clarifying :pray:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.