i used an array as the key here and it worked fine
@NeetCodeIO Жыл бұрын
Good catch. The reason that works in this case is our function is only called with integers, so JavaScript implicitly converts the array into a string, e.g. '[1, 2, 3]' -> '1, 2, 3'. But if you try doing that with an array of objects, it will be implicitly converted to this: ''[object Object],[object Object],[object Object']' Obviously, in that case the key would not be unique. JSON.stringify() prevents this bug, because it gives us the most precise string representation of the array/objects.
@julianelmasry9556 Жыл бұрын
@@NeetCodeIO thanks for the clarification
@Android-17 Жыл бұрын
@@NeetCodeIO thanks!
@Aashiqui-pf7ni11 ай бұрын
bro please help to study hard and understand the js concept more ,where I can study the concept in js
@Eliv-d Жыл бұрын
Your videos are so helpful ! thank you from bottom of my heart!!
@NeetCodeIO Жыл бұрын
Glad I could help =)
@komiljonyormurodov39796 ай бұрын
great explanation, thank you
@pranavkumar9175 Жыл бұрын
very nicely explained, thankyou so much.
@shoaibhasan4026 Жыл бұрын
thanks man for great explanation .
@ar.ventures Жыл бұрын
nit:- The Leetcode problem number in the title says 2629 but in fact is 2623. Might make it difficult for people searching for a solution by the problem number. Also, thanks for the daily uploads. They make us all better programmers each day - one bit at a time :)
@NeetCodeIO Жыл бұрын
My b, fixed!
@vixguy Жыл бұрын
Day 9 of doing the 30-day challenge with NeetCode
@NehaSingh292637 ай бұрын
thankyou so much it helps me alot
@chizuru1999 Жыл бұрын
I am an experienced JS developer (yes experienced for job tasks i mean 😂) but this is great for logic building. Thanks a lot 🫰 keep uploading. Also can you please share your website graph config? I want to take a look at it. It uses the antv x6 graph right?
@TheMarkBrut Жыл бұрын
2:22 like! I do not now same about React, because u now
@krateskim4169 Жыл бұрын
Thank you so much
@朴云峰 Жыл бұрын
let's say we memoized a function sum, should memoize(1,2,3) and memoize(3,2,1) be considered the same and the callCount be 1?
@navenkumarduraisamy6260 Жыл бұрын
Ideally not, it's not always the same fn that is passed as a parameter to memoize function
@Amar11115 Жыл бұрын
2:24 a fun moment 😆
@AyoubRABIYAE Жыл бұрын
Amazing
@teqarine5752 Жыл бұрын
in the stringify function, why do we use args, and not the spread operator ...args?
@janithrs10 ай бұрын
because args act as a single element but ...args act as multiple elements
@arin35375 ай бұрын
Did you solve memorize 2 ? I didnt find it :(
@navenkumarduraisamy6260 Жыл бұрын
Taking about the design pattern, Isn't this strategy design pattern? Because we could pass any parameter(strategy) to memoize.
@inanismailov Жыл бұрын
I see that on line 12 you have cache[key] = fn(...args); My question is, if cache is declared as a const, how are you able to add to it?
@inanismailov Жыл бұрын
I have answered my own question, using const simply means you cannot reassign the variable name. You CAN still mutate it.
@redwayne81729 ай бұрын
I have learnt frm your answer to your question . Thak you 😂😂😂😂
@gintokiblade14488 ай бұрын
const as in non changeable only applies to primitives and not for non primitive objects like arrays
@Android-17 Жыл бұрын
I used *args.join("-")* as the key which worked for this problem with integers. But *JSON.stringify()* is a better option. THANKS!
@anishkarthik4309 Жыл бұрын
what is difference between a) const key = args.toString(); and b) const key = JSON.stringify(args); ? why b) is faster than a) by 2-3 times always???
@StoneAge20908 Жыл бұрын
We can re convert to JSON object using JSON.parse().
@SeRoShadow10 ай бұрын
doesnt work ... . I get fn proto
@hoyinli7462 Жыл бұрын
2:25 if you are writing angular, why don't you go for typescript in daily js challenge? XD keep it up
@StoneAge20908 Жыл бұрын
What if order of arguments is different but values are same