5 kyu
Pipelining and composing functions
520 of 527user5363957
Description:
Let's see 2 ways of applying successive functions to an object:
The purpose of this kata is to think of this kind of code
var result = fn4(fn3(fn2(fn1(obj))));
in terms of pipelining or composition of functions.
- Pipelining
var result = pipeline(obj , fn1 , fn2 , fn3 , fn4);
for instance:
pipeline([1,2,3,4,5,6] // seed
, rest // first function to apply
, rest // second function to apply
, rest // ..
, rest
, first);
=> 5
- Composition: it should return a function that is the composition of a list of functions, where each function consumes the return value of the function that follows.
for instancevar compositionFn = compose(fn4, fn3, fn2, fn1); var result = compositionFn(obj);
var greet = function(name){ return "hi: " + name; }; var exclaim = function(statement){ return statement.toUpperCase() + "!"; }; var welcome = compose(greet, exclaim); welcome('moe'); => 'hi: MOE!'
Functional Programming
Fundamentals
Similar Kata:
Stats:
Created | Nov 29, 2013 |
Published | Nov 29, 2013 |
Warriors Trained | 1153 |
Total Skips | 315 |
Total Code Submissions | 4486 |
Total Times Completed | 527 |
JavaScript Completions | 520 |
Total Stars | 36 |
% of votes with a positive feedback rating | 83% of 96 |
Total "Very Satisfied" Votes | 72 |
Total "Somewhat Satisfied" Votes | 16 |
Total "Not Satisfied" Votes | 3 |