kolodny / exercises

Some basic javascript coding challenges and interview questions
4.23k stars 672 forks source link

Once and memoize #35

Closed phil-r closed 9 years ago

phil-r commented 9 years ago

Hi, what's the difference between those two exercices?

kolodny commented 9 years ago

Once is where you want a function to run only once, like a callback that can be invoked from multiple places, whereas memoize is where you want to know the return value of an expensive function like a complex math function, yet only want to do the intensive computation once, and reuse the saved results for further calls

phil-r commented 9 years ago

Thank you! Readmes are a bit confusing ;)

kolodny commented 9 years ago

I didn't realize the readmes were so similar. To elaborate on what I wrote above, once is more concerned about running the function, so even calling a once'd function with different arguments shouldn't call it again, in contrast, a memoize'd function will run for each unique arguments list