Created
August 28, 2012 15:36
-
-
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
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
sum . takeWhile (<10000) . filter odd . map (^2) $ [1..] |
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
var sum = 0, | |
i = 0, | |
n = 0; | |
while ((n = Math.pow(++i, 2)) < 1e4) { | |
i % 2 !== 0 && (sum += n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, that makes sense - I was wondering why the JS equivalent looked quite convoluted! :)