Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created May 17, 2017 15:48
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 ethagnawl/cd1fee68580bd6c33f168c5d896e71e3 to your computer and use it in GitHub Desktop.
Save ethagnawl/cd1fee68580bd6c33f168c5d896e71e3 to your computer and use it in GitHub Desktop.
list comprehension comparison haskell vs. javascript
// 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