Created
January 8, 2020 11:54
-
-
Save manuelgeek/2efce872f81ddbc160db7062356ca579 to your computer and use it in GitHub Desktop.
Your task is to add up letters to one letter. The function will be given a variable amount of arguments, each one being a letter to add. Notes: Letters will always be lowercase. Letters can overflow (see second to last example of the description) If no letters are given, the function should return 'z' fom https://www.codewars.com/kata/alphabetic…
This file contains hidden or 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
function addLetters() { | |
var alphabet = "abcdefghijklmnopqrstuvwxyz".split(''); | |
var sum = 0; | |
if(arguments.length === 0){ | |
console.log(alphabet[26-1]); | |
return alphabet[26-1]; | |
} | |
for (var i = 0; i < arguments.length; ++i){ | |
let l = arguments[i].toLowerCase(); | |
let t = alphabet.indexOf(l) + 1; | |
sum = sum + t; | |
} | |
if(sum > 26){ | |
sum = sum % 26; | |
} | |
console.log(alphabet[sum - 1]) | |
return alphabet[sum - 1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment