Why is it not working?

Tell us what’s happening:
It returns function?
Your code so far

function dropElements(arr, func) {
  var largest = 0;
  for (var i = 0; i < arr.length; i++) {
    if (largest < arr[i]) {
      largest = arr[i];
   var n = 1;
 var newArr = [];
  for (var i = 0; i < largest; i++) {
    if (func(i) == true) {
       return newArr = arr.splice(i - 1);
    } else if (func(n) == true){
     return [1, 0, 1];
  return newArr;

dropElements([1, 2, 3, 4], function(n) {return n >= 3;});
console.log(dropElements([0, 1, 0, 1], function(n) {return n === 1;}));
console.log([1, 2, 3], function(n) {return n > 0;})
   **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15.

Challenge: Drop it

Link to the challenge:

I am not sure what any of that code is supposed to do, but it looks like you are trying to hard code answers to pass the test instead of solve the problem programmatically.

Can you explain, in words, what you think this challenge is asking you to do?

1 Like

loop the array and if the function number n which is for example equal to 1, then array with index that has number 1 gives all values. starting from number 1.

What do you mean by this? Your function only receives one function from the user.

1 Like

function(n) {return n === 1;})

then if (func(i) == true) { return newArr = arr.splice(i - 1); }

Just realised I took the challenge wrong, when I give it the value i.

func is one input to your function.

Given the array arr , iterate through and remove each element starting from the first element (the 0 index) until the function func returns true when the iterated element is passed through it.

You need to apply func to the elements of your array, and func will either return true or false. It should not matter to your function what the users pass in as func.

1 Like

Removed variable i, added arr[i] instead,
if (func(arr[i]) == true)

took away - 1
return newArr = arr.slice(i);

Don’t understand how that worked.
Thanks for the help.

you should not assign inside the return stament, it works but it does not really make sense to do it

1 Like

Thanks for pointing that out.

You should also be able to cut out all that stuff with largest

1 Like

Is this really correct?
Reason why I did this is because n is strictly equal to 1

Yes, works. I added 100 instead.

No, this is not correct. This is hardcoding an answer to pass a test rather than making a function work programmatically.

1 Like

You shouldn’t need to know the largest value, or some number that may be a largest value.

1 Like

It’s so the for loop works.

You like this code?

function dropElements(arr, func) {
  for (var i = 0; i < arr.length; i++) {
    if (func(arr[i]) == true) {
       return arr.slice(i);
  return [];

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

You still shouldn’t need it for the loop.

There we go, that’s much tidier.

1 Like

you have still this extra, but really really better