5 kyu
Compose functions (T Combinator)
2,241 of 2,287kylehill
Description:
Let's make a function called compose that accepts a value as a parameter, as well as any number of functions as additional parameters.
The function will return the value that results from the first parameter being used as a parameter for all of the accepted function parameters in turn.
compose(n, f1, f2, f3 , fn) // === fn(...(f3(f2(f1(n)))))
So:
var doubleTheValue = function(val) { return val * 2; }
var addOneToTheValue = function(val) { return val + 1; }
compose(5, doubleTheValue) // should === 10
compose(5, doubleTheValue, addOneToTheValue) // should === 11
If only a single parameter is passed in, return that parameter.
compose(n) = n
Functional Programming
Fundamentals
Similar Kata:
Stats:
Created | Aug 1, 2013 |
Published | Aug 1, 2013 |
Warriors Trained | 3717 |
Total Skips | 654 |
Total Code Submissions | 12059 |
Total Times Completed | 2287 |
JavaScript Completions | 2241 |
Total Stars | 46 |
% of votes with a positive feedback rating | 92% of 243 |
Total "Very Satisfied" Votes | 205 |
Total "Somewhat Satisfied" Votes | 36 |
Total "Not Satisfied" Votes | 2 |