4 kyu
Default Arguments
1,256 of 1,330xcthulhu
Description:
Write a function defaultArguments
. It takes a function as an argument, along with an object containing default values for that function's arguments, and returns another function which defaults to the right values.
You cannot assume that the function's arguments have any particular names.
You should be able to call defaultArguments
repeatedly to change the defaults.
function add(a,b) { return a+b;};
var add_ = defaultArguments(add,{b:9});
add_(10); // returns 19
add_(10,7); // returns 17
add_(); // returns NaN
add_ = defaultArguments(add_,{b:3, a:2});
add_(10); // returns 13 now
add_(); // returns 5
add_ = defaultArguments(add_,{c:3}); // doesn't do anything, since c isn't an argument
add_(10); // returns NaN
add_(10,10); // returns 20
HINT: This problem requires using Fuction.prototype.toString()
in order to extract a function's argument list
Functional Programming
Metaprogramming
Similar Kata:
Stats:
Created | Oct 17, 2013 |
Published | Oct 17, 2013 |
Warriors Trained | 8466 |
Total Skips | 3056 |
Total Code Submissions | 44886 |
Total Times Completed | 1330 |
JavaScript Completions | 1256 |
CoffeeScript Completions | 78 |
Total Stars | 380 |
% of votes with a positive feedback rating | 82% of 223 |
Total "Very Satisfied" Votes | 160 |
Total "Somewhat Satisfied" Votes | 46 |
Total "Not Satisfied" Votes | 17 |