Lodash Library

Hi Everyone
I’m trying working on the challenge of recreating the Lodash library. I got stuck on the following object Method: findKeys()

For I still can’t figure why I can’t retrieved the key.

So far I have fulfil condition one and three, but the main one is not working.

Thanks a lot for your help =) !

Your code has overwritten the function that was passed in. It is that function that we want to invoke (one assumes), not one we create with the same name.

What is the objective of the method? Can you please post a link to the exercise so we can delve into the instructions?

Thank you for that! so here is the link:

https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/pjs-javascript-capstone/projects/lodash

and here it’s what the method should do:

Here is a summary of what your method should do:

  • .findKey() takes two arguments: an object and a predicate function — a function that returns a boolean value
  • .findKey() iterates through each key / value pair in the provided object and calls the predicate function with the value
  • .findKey() returns the first key that has a value that returns a truthy value from the predicate function
  • .findKey() returns undefined if no values return truthy values from the predicate function

thanks again for your help!

1 Like

Which confirms the assumption that one of the parameters is a function. Said function will supply the role expected by findKey.

findKey(object,func)

A predicate is pretty straight forward. Have it look at something and return whether it is or it isn’t the desired state.

x => x.startsWith("A')

As we iterate over the keys of the object, they each become the x in the parameter.

now see it, it makes much more sense now. I made it worked thanks to your explanation. thank you so much for your help! it was really helpful!

1 Like