Skip to content

Instantly share code, notes, and snippets.

@TexRx
Forked from LeaVerou/js-under-pressure.js
Created October 11, 2013 18:47
Show Gist options
  • Save TexRx/6939990 to your computer and use it in GitHub Desktop.
Save TexRx/6939990 to your computer and use it in GitHub Desktop.
// DISCLAIMER: This is not necessarily good code. It’s just code that I wrote
// as quickly as possible to do each task.
// 1
return 2*i;
// 2
return !(i%2);
// 3
return (i.match(/\.(.+)$/) || [,false])[1];
// 4
var l = '';
for (var n=0; n<i.length; n++) {
if (typeof i[n] == 'string' && i[n].length > l.length) {
l = i[n];
}
}
return l;
// 5
function arraySum(a) {
var sum = 0;
for (var i=0; i<a.length; i++) {
var n = a[i];
if (n === +n) {
sum += n;
}
else if (Array.isArray(n)) {
sum += arraySum(n);
}
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment