Skip to content

Instantly share code, notes, and snippets.

@wteuber
Last active December 25, 2015 02:29
Show Gist options
  • Select an option

  • Save wteuber/6903101 to your computer and use it in GitHub Desktop.

Select an option

Save wteuber/6903101 to your computer and use it in GitHub Desktop.
/*jslint indent: 2 */
// http://toys.usvsth3m.com/javascript-under-pressure/
function doubleInteger(i) {
'use strict';
// i will be an integer. Double it and return it.
return i * 2;
}
function isNumberEven(i) {
'use strict';
// i will be an integer. Return true if it's even, and false if it isn't.
return (i % 2) === 0;
}
function getFileExtension(i) {
'use strict';
// 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
if (/\./.test(i)) {
return i.split(/\./).pop();
}
return false;
}
function longestString(i) {
'use strict';
// i will be an array.
// return the longest string in the array
return i.sort(function (a, b) {
if (typeof b !== 'string') {
return 1;
}
return (a.length > b.length) ? 1 : -1;
}).pop();
}
var arraySum = function tmp(i) {
'use strict';
// 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 e, s = 0;
for (e = 0; e < i.length; e += 1) {
if (typeof i[e] === 'number') {
s += i[e];
} else if (typeof i[e] === 'object' && i[e].length) {
s += tmp(i[e]);
}
}
return s;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment