Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Created August 28, 2012 15:36
Show Gist options
  • Save JamieMason/3499183 to your computer and use it in GitHub Desktop.
Save JamieMason/3499183 to your computer and use it in GitHub Desktop.
Haskell vs JavaScript: find the sum of all odd squares that are smaller than 10000
sum . takeWhile (<10000) . filter odd . map (^2) $ [1..]
var sum = 0,
i = 0,
n = 0;
while ((n = Math.pow(++i, 2)) < 1e4) {
i % 2 !== 0 && (sum += n);
}
@makeusabrew
Copy link

Ah, that makes sense - I was wondering why the JS equivalent looked quite convoluted! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment