Skip to content

Instantly share code, notes, and snippets.

@manuelgeek
Created January 8, 2020 11:54
Show Gist options
  • Save manuelgeek/2efce872f81ddbc160db7062356ca579 to your computer and use it in GitHub Desktop.
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…
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