Created
May 17, 2017 15:48
-
-
Save ethagnawl/cd1fee68580bd6c33f168c5d896e71e3 to your computer and use it in GitHub Desktop.
list comprehension comparison haskell vs. javascript
This file contains 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
// equivalent haskell using list comprehension syntax | |
// [x^2 | x <- [1..10], rem x 2 == 0] | |
var list = []; | |
// no ranges ... | |
for (var i = 1; i < 11; i += 1) { | |
list.push(i); | |
} | |
var evenSquares = list | |
.filter(function (i) { | |
return i % 2 == 0; | |
}).map(function (i) { | |
return i * i; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment