Created
May 14, 2014 17:20
-
-
Save ajrob/afbda7aff7e9f96e4144 to your computer and use it in GitHub Desktop.
You Can't 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
function doubleInteger(i) { | |
// i will be an integer. Double it and return it. | |
return i *= 2; | |
} |
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
function isNumberEven(i) { | |
// i will be an integer. Return true if it's even, and false if it isn't. | |
return i%2 === 0 ? true : false; | |
} |
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
function getFileExtension(i) { | |
// i will be a string, but it may not have a file extension. | |
// return the file extension (with no period) if it has one, otherwise false | |
var exp = /^.*\.(.*)/; | |
return i.match(exp) ? i.match(exp)[1] : false; | |
} |
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
function longestString(i) { | |
// i will be an array. | |
// return the longest string in the array | |
var max = ""; | |
i.forEach(function(element){ | |
if((typeof element) === 'string'){ | |
if(element.length > max.length){ | |
max = element; | |
} | |
} | |
}); | |
return max; | |
} |
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
function arraySum(i) { | |
// i will be an array, containing integers, strings and/or arrays like itself. | |
// Sum all the integers you find, anywhere in the nest of arrays. | |
var sum = 0; | |
function burrowInto(array) { | |
array.forEach(function(element){ | |
if ((typeof element) === 'number'){ | |
sum += element; | |
} else if (Array.isArray(element)){ | |
burrowInto(element); | |
} | |
}) | |
} | |
burrowInto(i); | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment