Skip to content

Instantly share code, notes, and snippets.

@passcod
Last active December 29, 2015 07:58
Show Gist options
  • Select an option

  • Save passcod/7639695 to your computer and use it in GitHub Desktop.

Select an option

Save passcod/7639695 to your computer and use it in GitHub Desktop.
Functional-style answers for You Can('t) Javascript Under Pressure, v1.0
function doubleInteger(i) {
return i * 2;
}
function isNumberEven(i) {
return !(i % 2);
}
function getFileExtension(i) {
var s = i.split('.');
return s.length > 1 ? s.pop() : false;
}
function longestString(i) {
return i.sort(function(a, b) {
return typeof a == 'string' && typeof b == 'string' ? a.length - b.length : -1;
}).pop();
}
function arraySum(i) {
return i.reduce(function(memo, a) {
return memo + (
typeof a === 'number' ? a : (
Array.isArray(a) ? arraySum(a) : 0
)
);
}, 0);
}
@passcod

passcod commented Nov 26, 2013

Copy link
Copy Markdown
Author

Alternate versions and performance tests for Level 4: http://jsperf.com/ycjup-level4

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