Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rubenribeiro/673918e85960993792ea to your computer and use it in GitHub Desktop.
Save rubenribeiro/673918e85960993792ea 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