Skip to content

Instantly share code, notes, and snippets.

@peelman
Created October 7, 2013 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peelman/6873796 to your computer and use it in GitHub Desktop.
Save peelman/6873796 to your computer and use it in GitHub Desktop.
Code Results from Under Pressure
function doubleInteger(i) {
// i will be an integer. Double it and return it.
i = i*2
return i;
}
function isNumberEven(i) {
// i will be an integer. Return true if it's even, and false if it isn't.
return i%2 ? false : true
}
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 ext = i.split('.').pop();
if(ext == i) return "";
return ext;
}
function longestString(i) {
// i will be an array.
// return the longest string in the array
var longest = ''
for (var x in i) {
if (typeof(i[x]) === 'string') {
if (longest.length < i[x].length) {
longest = i[x]
}
}
}
return longest
}
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
for (var x in i) {
if (Array.isArray(i[x])) {
sum += arraySum(i[x])
} else if (typeof(i[x]) === 'number') {
sum += i[x]
}
}
return sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment