0

Please help me!!!

Searching through deep nested object using recursions. https://code.sololearn.com/cA9a5a11a9A7/?ref=app

11th Jul 2021, 9:30 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
10 ответов
+ 2
two possible solutions: first one return true if first argument is not an object and equals second argument... function contains(obj, item) { return typeof obj=="object" ? Object.entries(obj).some( ([k,v]) => contains(v, item) ) : obj == item; } second one return undefined if first argument is not an object, else return true or false according to if one nested value / object contains second argument: function contains(obj, item) { if (typeof(obj)!="object") return; return Object.entries(obj).some(([k,v]) => typeof v=="object" ? contains(v, item) : v == item ); } if you want to compare values with item strictly (no automatic cast when comparing -- ie: 42 !== "42"), use triple equal sign to compare obj/v against item, rather than double equal sign...
11th Jul 2021, 10:07 PM
visph
visph - avatar
+ 2
visph I'm now seeing this. I never noticed! So sorry bro. The best mark also that I removed was a mistake. It wasn't intentional!
12th Jul 2021, 4:09 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
+ 2
visph but why would I remove it on purpose? You answered well and it helped me a lot. I wouldn't be that ungrateful!
12th Jul 2021, 4:17 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
+ 1
visph my good friend. Please Another question. These days I've been learning a lot about recursions and solving many questions online.
11th Jul 2021, 9:31 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
+ 1
visph thanks a million!!! , good friend ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️ ☺️
11th Jul 2021, 10:17 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
+ 1
visph hi. It keeps giving me "false" regardless of the item as argument
11th Jul 2021, 10:30 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
+ 1
my bad: I've too quickly turned my versions using Object.keys() to version nearest to your using Object.entries() ^^ previous answer corrected: you just need to put "k,v" inside square brackets to destructure value passed as callback argument of some() method ;)
11th Jul 2021, 10:42 PM
visph
visph - avatar
+ 1
visph it worked now!! 🎊 🎊 🎊 😄😄😄😄😄😄. Thanks again 😊😊😊😊
11th Jul 2021, 11:05 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
+ 1
why removing best answer mark???
12th Jul 2021, 6:39 AM
visph
visph - avatar
+ 1
well, I hope you're not lying (it's difficult to believe that it was a mistake)... and that you will not remove it again later (or delete the thread): I'm tired of user who set and remove best answer mark (or delete thread) without reasons, even if I help those who didn't set best answer at all ^^
12th Jul 2021, 4:14 PM
visph
visph - avatar