Last active
August 29, 2015 14:26
-
-
Save bwestergard/d49a53fb5c8031605e37 to your computer and use it in GitHub Desktop.
Ramda "supercompiler"
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
// Ramda provides one, but just for verbosity | |
var add = function (x,y) { return x + y; }; | |
var square = function (x) { return x * x; }; | |
// Redundant looping | |
var sumSquares = R.pipe( | |
R.map(square), | |
R.reduce(add, 0) | |
); | |
// Drop one loop | |
var addSquare = function (x,y) { return x + square(y); }; | |
var sumSquaresFast = R.reduce(addSquare, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment