5 kyu

Function Cache

10,003 of 10,077BattleRattle

Description:

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 with these arguments
Fundamentals

Stats:

CreatedOct 8, 2013
PublishedOct 8, 2013
Warriors Trained21234
Total Skips4146
Total Code Submissions158940
Total Times Completed10077
JavaScript Completions10003
Total Stars345
% of votes with a positive feedback rating86% of 567
Total "Very Satisfied" Votes444
Total "Somewhat Satisfied" Votes88
Total "Not Satisfied" Votes35
Ad
Contributors
  • BattleRattle Avatar
  • jhoffner Avatar
  • hobovsky Avatar
Ad