Implement an Element Skipper - Implement an Element Skipper

Tell us what’s happening:

i need help here,
iam trying but i think iam lost ,
i donno the way that i can pass test 3 and test number 7,
any hint please , thanks for you all

Your code so far

function dropElements(arr, func) {
  
  
  let result = []
  for(let i = 0; i < arr.length; i++) {

     if(func(arr[i])) {

     result.push(arr[i])
     }

    // console.log(func(arr[i]))
  }
  // for(const num of arr) {
  //   console.log(num)
  // }
  //  arr.forEach(e => func(e) ? result.push(e) : '')
  return result
}
console.log(dropElements([1, 2, 3, 4], function(n) {return n >= 3;}))

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Implement an Element Skipper - Implement an Element Skipper

Can you say what test 3 and 7 are?

Which specific lines of your code do you think meet those requirements?

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

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

i will tell you what logic i can’t get ,
if i used func(element)
it should return true or false when i make my condition i remove all what result is false and that’s not required,
the required is to remove till the first true and return the rest elements even if it is not met

that’s not completely true, you need to remove elements until you find the first one that satisfy the test, then you need to return that and the elements after that without removing anything else

Ok, and have you tried to make your loop do this yet? What did your try look like?

i only could remove all the returning falsy values on func i couldn’t execute it like it required.

The instructions do not ask you to remove all falsy values though.

i see , i just my brain stopped working , maybe i need to use slice or splice methods somehow but i still don’t get it

You do not need to use splice or slice. You can use a loop. But you need to understand what the instructions are asking for before you can code something up that does what the instructions want.

1 Like

i got it, i need to remove all falsy values till i meet first truthy value i return the rest for the array till the end

maybe i should use shift method somehow

You can use a plain old for loop if that’s what you’re comfortable with. You don’t need a magic method.

ok, thanks for encourage me . i think it’s easier than iam thinking :slight_smile:

i think i just need a time to get recover, because the doctor put medicated eye drop in my eyes and i see fog somehow

then go rest… . 

iam burning excited to get pass on those challenges

i did it, i knew i will pass it since you told me i can use plain loop, you pushed the stress away from me, i couldn’t do it without your words.
thank you

1 Like

Nice work!

It helps to remember sometimes that most of the special methods like splice and slice really are pre-made combinations of if and for

1 Like

i will keep it in mind , thank you