Skip to content

Instantly share code, notes, and snippets.

@Zirak
Created October 3, 2013 20:26
Show Gist options
  • Select an option

  • Save Zirak/6816574 to your computer and use it in GitHub Desktop.

Select an option

Save Zirak/6816574 to your computer and use it in GitHub Desktop.
function doubleInteger(i) {
// i will be an integer. Double it and return it.
return i + i;
}
function isNumberEven(i) {
// i will be an integer. Return true if it's even, and false if it isn't.
return !(i % 2)
}
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 index = i.indexOf('.');
return index > -1 ? i.slice(index+1) : false;
}
function longestString(i) {
// i will be an array.
// return the longest string in the array
return i.reduce(function (ret, item) {
if (!item.toUpperCase) {
return ret;
}
return ret.length > item.length ? ret : item;
})
}
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.
return i.reduce(function (ret, item) {
if (Array.isArray(item)) {
return ret + arraySum(item);
}
return item.toFixed ? ret + item : ret;
}, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment