Last active
December 25, 2015 06:49
-
-
Save LeaVerou/6934569 to your computer and use it in GitHub Desktop.
My answers to http://toys.usvsth3m.com/javascript-under-pressure/
This file contains 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
// 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
@iamJoeTaylor: What does that mean?