Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MikeDigitize/fcc2c02c12d471e6dbfd to your computer and use it in GitHub Desktop.
Save MikeDigitize/fcc2c02c12d471e6dbfd to your computer and use it in GitHub Desktop.
Some coding challenges for the AO front end team who are learning JavaScript
/*
The function should convert the name into a number (somehow?) and multiply it by the current time.
The answer should be divided by 2. If that number is even, the person is cool, otherwise they're not :(
*/
function arrayOfStringsToNum(arr) {
var alphabet = strToArray("abcdefghijklmnopqrstuvwxyz");
return arr.reduce((a, b) => a += alphabet.indexOf(b.toLowerCase()), 0);
}
function strToArray(str) {
return str.split("").filter(letter => !~letter.indexOf(" "));
}
function getTime() {
return new Date().getTime();
}
function divide(by) {
return function(num) {
return Math.floor(num / by);
}
}
function isEven(num) {
return num % 2 === 0;
}
function isCool(str) {
return isEven(divide(2)(arrayOfStringsToNum(strToArray(str)) * getTime()));
}
var mike = "Michael Chadwick";
console.log(isCool(mike));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment