Skip to content

Commit 5cfc980

Browse files
committed
Added and completed "memoize" for Underbar.
1 parent 3fbb437 commit 5cfc980

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/underbar.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ var _ = {};
315315
// already computed the result for the given argument and return that value
316316
// instead if possible.
317317
_.memoize = function(func) {
318+
var results = {};
319+
320+
return function() {
321+
var args=Array.prototype.slice.call(arguments);
322+
if (!(args in results)) {
323+
results[args] = func.apply(this, args);
324+
}
325+
return results[args];
326+
};
318327
};
319328

320329
// Delays a function for the given number of milliseconds, and then calls

0 commit comments

Comments
 (0)