Skip to content

Instantly share code, notes, and snippets.

@angus-c
Created November 29, 2014 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angus-c/92fe9c3aa745d0669efd to your computer and use it in GitHub Desktop.
Save angus-c/92fe9c3aa745d0669efd to your computer and use it in GitHub Desktop.
<!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>
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