Created
January 3, 2016 20:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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