Skip to content

Instantly share code, notes, and snippets.

Created December 6, 2015 06:36
Show Gist options
  • Save anonymous/39eda8f8efd6525d1f11 to your computer and use it in GitHub Desktop.
Save anonymous/39eda8f8efd6525d1f11 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dannycoder 's solution for Bonfire: Missing letters
// Bonfire: Missing letters
// Author: @dannycoder
// Challenge: http://www.freecodecamp.com/challenges/bonfire-missing-letters#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function fearNotLetter(str) {
//detect if the letter is missing
if(str.length === (str.charCodeAt(str.length - 1) - str.charCodeAt(0) + 1 )){
return undefined;
} else {
//track down the missing letter
for(var i = str.charCodeAt(0), j = 0; i <= str.charCodeAt(str.length -1); i++, j++) {
//return the missing letter
if(String.fromCharCode(str.charCodeAt(j)) !== String.fromCharCode(i)) {
return String.fromCharCode(i);
}
}
}
}
fearNotLetter("abce");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment