Memoize - Leetcode 2623 - JavaScript 30-Day Challenge

  Рет қаралды 14,731

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 36
@julianelmasry9556
@julianelmasry9556 Жыл бұрын
i used an array as the key here and it worked fine
@NeetCodeIO
@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
@julianelmasry9556 Жыл бұрын
@@NeetCodeIO thanks for the clarification
@Android-17
@Android-17 Жыл бұрын
@@NeetCodeIO thanks!
@Aashiqui-pf7ni
@Aashiqui-pf7ni 11 ай бұрын
bro please help to study hard and understand the js concept more ,where I can study the concept in js
@Eliv-d
@Eliv-d Жыл бұрын
Your videos are so helpful ! thank you from bottom of my heart!!
@NeetCodeIO
@NeetCodeIO Жыл бұрын
Glad I could help =)
@komiljonyormurodov3979
@komiljonyormurodov3979 6 ай бұрын
great explanation, thank you
@pranavkumar9175
@pranavkumar9175 Жыл бұрын
very nicely explained, thankyou so much.
@shoaibhasan4026
@shoaibhasan4026 Жыл бұрын
thanks man for great explanation .
@ar.ventures
@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
@NeetCodeIO Жыл бұрын
My b, fixed!
@vixguy
@vixguy Жыл бұрын
Day 9 of doing the 30-day challenge with NeetCode
@NehaSingh29263
@NehaSingh29263 7 ай бұрын
thankyou so much it helps me alot
@chizuru1999
@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
@TheMarkBrut Жыл бұрын
2:22 like! I do not now same about React, because u now
@krateskim4169
@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
@navenkumarduraisamy6260 Жыл бұрын
Ideally not, it's not always the same fn that is passed as a parameter to memoize function
@Amar11115
@Amar11115 Жыл бұрын
2:24 a fun moment 😆
@AyoubRABIYAE
@AyoubRABIYAE Жыл бұрын
Amazing
@teqarine5752
@teqarine5752 Жыл бұрын
in the stringify function, why do we use args, and not the spread operator ...args?
@janithrs
@janithrs 10 ай бұрын
because args act as a single element but ...args act as multiple elements
@arin3537
@arin3537 5 ай бұрын
Did you solve memorize 2 ? I didnt find it :(
@navenkumarduraisamy6260
@navenkumarduraisamy6260 Жыл бұрын
Taking about the design pattern, Isn't this strategy design pattern? Because we could pass any parameter(strategy) to memoize.
@inanismailov
@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
@inanismailov Жыл бұрын
I have answered my own question, using const simply means you cannot reassign the variable name. You CAN still mutate it.
@redwayne8172
@redwayne8172 9 ай бұрын
I have learnt frm your answer to your question . Thak you 😂😂😂😂
@gintokiblade1448
@gintokiblade1448 8 ай бұрын
const as in non changeable only applies to primitives and not for non primitive objects like arrays
@Android-17
@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
@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
@StoneAge20908 Жыл бұрын
We can re convert to JSON object using JSON.parse().
@SeRoShadow
@SeRoShadow 10 ай бұрын
doesnt work ... . I get fn proto
@hoyinli7462
@hoyinli7462 Жыл бұрын
2:25 if you are writing angular, why don't you go for typescript in daily js challenge? XD keep it up
@StoneAge20908
@StoneAge20908 Жыл бұрын
What if order of arguments is different but values are same
@aaa-os3pj
@aaa-os3pj 2 ай бұрын
Different key obviously can't use cached value
Curry - Leetcode 2632 - JavaScript 30-Day Challenge
14:22
NeetCodeIO
Рет қаралды 10 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,8 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Sleep - Leetcode 2621 - JavaScript 30-Day Challenge
19:13
NeetCodeIO
Рет қаралды 10 М.
JavaScript Memoization Made Simple!
11:22
The Code Creative
Рет қаралды 6 М.
How I Got Good at Coding Interviews
6:29
NeetCode
Рет қаралды 1,7 МЛН
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 361 М.
Promise Time Limit - Leetcode 2637 - JavaScript 30-Day Challenge
12:56
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН