Doe de onderstaande test ;-)
http://toys.usvsth3m.com/javascript-under-pressure/
7:45 was mijn tijd
1.053 views
function doubleInteger(i) {
// i will be an integer. Double it and return it.
return i * 2;
}
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
if (-1 == i.indexOf('.')) {
return false;
}
var parts = i.split('.');
return parts[parts.length - 1];
}
function longestString(i) {
// i will be an array.
// return the longest string in the array
var value = '';
for (var ii = 0; ii <= i.length; ii++) {
if (typeof i[ii] == 'string' && i[ii].length >= value.length) {
value = i[ii];
}
}
return value;
}
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 ii = 0; ii <= i.length; ii++) {
if (typeof i[ii] == 'number') {
sum += i[ii];
} else if (typeof i[ii] == 'object') {
sum += arraySum(i[ii]);
}
}
return sum;
}
function doubleInteger(i) {
// i will be an integer. Double it and return it.
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 === 0;
}
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
return i.split('.')[1] || false;
}
function longestString(i) {
// i will be an array.
// return the longest string in the array
var longest = 0;
var string;
i.forEach(function (ie) {
if (typeof ie !== 'string') {
return;
}
var len = 0;
while(ie.charAt(++len) !== '');
if (len > longest) {
string = ie;
longest = len;
}
});
return string;
}
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;
i.forEach(function (ie) {
switch (typeof ie) {
case 'number':
sum += ie;
break;
case 'object':
sum += arraySum(ie);
break;
}
});
return sum;
}
function isNumberEven(i) {
// i will be an integer. Return true if it's even, and false if it isn't.
return i % 2 == 0;
}