Lodash dropWhile exercise not dropping the right number of elements

Hi there,

Trying to slog through the lodash exercise and it seems my code is calculating the wrong dropNumber or something?
This is my first post - I did try to search for a solution, but I couldn’t find one - and I don’t know if I’m formatting the question properly!

dropWhile(array, predicate) {
      let dropNumber = array.findIndex((element, index) =>{!predicate(element, index, array)});
      let newArray = this.drop(array, dropNumber);
      return newArray
    },

The error message I get is…
_.dropWhile() Tests:
1 - _.dropWhile() is defined - Passed!
2 - Returns an array - Passed!
3 - Drops elements until predicate function returns falsy - Failed: _.dropWhile([1, 2, 0, 4], indexIsSmallerThanElement returned [ 4 ] instead of [ 0, 4 ].

I’m not sure why this is happening - I’m sure it’s got something to do with 0 indexing or something - or I’ve somehow made it drop the element and then return the rest, instead of keeping the element which is the trigger?

Thanks,

m

Missing explicit return inside the curly braces. Remove the braces to gain implicit return.

ahhh! Many thanks.

What should I add inside the braces to make the return explicit? Obviously it’s easier to remove them and just do the implicit thing, but I think I would learn more by knowing the answer to that question.

:slight_smile:

... => {
  return !...
}

When braces are included we have to use ES5 syntax.

1 Like