-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction Cache.js
More file actions
16 lines (11 loc) · 844 Bytes
/
Function Cache.js
File metadata and controls
16 lines (11 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* If you are calculating complex things or execute time-consuming API calls, you sometimes want to cache the results. In this case we want you to create a function wrapper, which takes a function and caches its results depending on the arguments, that were applied to the function.
Usage example:
var complexFunction = function(arg1, arg2) { /* complex calculation in here / };
var cachedFunction = cache(complexFunction);
cachedFunction('foo', 'bar'); // complex function should be executed
cachedFunction('foo', 'bar'); // complex function should not be invoked again, instead the cached result should be returned
cachedFunction('foo', 'baz'); // should be executed, because the method wasn't invoked before w */
function cache(func) {}
console.log(cache('foo', 'bar'))
console.log(cache('foo', 'bar'))
console.log(cache('foo', 'baz'))