Created
November 29, 2014 19:26
-
-
Save angus-c/92fe9c3aa745d0669efd to your computer and use it in GitHub Desktop.
// source http://jsbin.com/wobamaqora
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function compose(f,g) { | |
return function composed(x) { | |
return f(g(x)); | |
}; | |
} | |
var square = function(x){return x * x}; | |
var add4 = function(x){return x + 4}; | |
var add4AndSquare = compose(square, add4); | |
add4AndSquare(4); //64 | |
var pipe = function() { | |
return [].slice.call(arguments).reduceRight(compose); | |
} | |
var squareAndAdd4 = pipe(square, add4); | |
squareAndAdd4(4); //20 | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function compose(f,g) { | |
return function composed(x) { | |
return f(g(x)); | |
}; | |
} | |
var square = function(x){return x * x}; | |
var add4 = function(x){return x + 4}; | |
var add4AndSquare = compose(square, add4); | |
add4AndSquare(4); //64 | |
var pipe = function() { | |
return [].slice.call(arguments).reduceRight(compose); | |
} | |
var squareAndAdd4 = pipe(square, add4); | |
squareAndAdd4(4); //20 | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compose(f,g) { | |
return function composed(x) { | |
return f(g(x)); | |
}; | |
} | |
var square = function(x){return x * x}; | |
var add4 = function(x){return x + 4}; | |
var add4AndSquare = compose(square, add4); | |
add4AndSquare(4); //64 | |
var pipe = function() { | |
return [].slice.call(arguments).reduceRight(compose); | |
} | |
var squareAndAdd4 = pipe(square, add4); | |
squareAndAdd4(4); //20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment