Last active
December 29, 2015 07:58
-
-
Save passcod/7639695 to your computer and use it in GitHub Desktop.
Functional-style answers for You Can('t) Javascript Under Pressure, v1.0
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
| function doubleInteger(i) { | |
| return i * 2; | |
| } |
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
| function isNumberEven(i) { | |
| return !(i % 2); | |
| } |
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
| function getFileExtension(i) { | |
| var s = i.split('.'); | |
| return s.length > 1 ? s.pop() : false; | |
| } |
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
| function longestString(i) { | |
| return i.sort(function(a, b) { | |
| return typeof a == 'string' && typeof b == 'string' ? a.length - b.length : -1; | |
| }).pop(); | |
| } |
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
| function arraySum(i) { | |
| return i.reduce(function(memo, a) { | |
| return memo + ( | |
| typeof a === 'number' ? a : ( | |
| Array.isArray(a) ? arraySum(a) : 0 | |
| ) | |
| ); | |
| }, 0); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternate versions and performance tests for Level 4: http://jsperf.com/ycjup-level4