Practice project : lodash problem

Hi! so I have the following problem with this:

so at the method .has() (edit: it’s findKey() actually) my code fails the 2nd test with a message saying : returns key instead of key:smiley:

is it a bug or am I missing something? the code should be fine, I think.

Thanks for reading!


Can you post your code for the has() method?

In my project, it shows the 2nd test for the has() method makes sure the following returns true:

_.has({"key": "value"}, "key")

If I change my method to fail, it would still give a message including: returned whatever instead of true. With whatever being what my function incorrectly returned. So I’m not sure why your failure message didn’t include true for the 2nd test or false for the 3rd.

whoops, it was findKey not has, sorry.
not in front of my PC so mobile version:!)

Look closely at your return statement. You’re mistakenly returning an array that includes the key rather than just the key. Once you fix that issue, your tests will pass.

Although the tests will pass, your method would not work properly for objects with more than one key/value pair. Your for loop never gets to iterate to the next key because you return undefined if the first value isn’t a match. You could move that after the for loop code.

1 Like

oh gee, I didn’t see that, and no idea why I did that, thank you!
also, originally the return undefined was after the for loop, but I started messing around with it while trying to figure out the fail.
thanks again!

1 Like