Re-creating the lodash library- dropwhile()


#1

I’ve been working on the dropwhile() section of the recreating the lodash library project.
https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/pjs-javascript-capstone/projects/lodash
I’ve tried different ways but it keeps saying there’s a problem with the drop() method that I tried to use in the dropWhile() method using this.drop(). I’m confused about what I am to do in this section I don’t understand what this method does. I even tried following the directions in the implement _.dropWhile() part but it still gives an error like - arr.slice() is not a function. I’ve also searched to see if there are any solutions on the forum but there is none.

Here’s my dropWhile() code

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

And here’s my _.drop() code

drop(arr, dropNum){
    if(dropNum === undefined){
      dropNum = 1;
    };
    let droppedArray = arr.slice(dropNum, arr.length)
    return droppedArray;

I’ll appreciate if anyone can help me out


#2

This variable is never referenced. Inside the function do we really want to return element? Check the instructions carefully.


#3

Then that is what to investigate, isn’t it? That’s the way forward. You’ll need to start by figuring out what is happening differently from what should happen. If this is how it is described:

Then that tells you a lot! You’ll have to consider whether it’s supposed to be a function, in which case arr probably doesn’t refer to an arr at all, or you overwrote that attribute - or if it’s not supposed to be a function, then you shouldn’t be calling it.


#5

Hi! I’m having the same problem -> .slice() not a function. This is my code:

drop(array, n) {
if (n === undefined) {
n = 1;
}
let droppedArray = array.slice(n);
return droppedArray;
},
dropWhile(array, predicate) {
let dropNumber = array.findIndex(function (element, index) {
return !predicate(element, index, array)
});
let droppedArray = this.drop(dropNumber);
return droppedArray;
}

Thanks for help!