Created
December 6, 2015 06:36
-
-
Save anonymous/39eda8f8efd6525d1f11 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dannycoder 's solution for Bonfire: Missing letters
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
// 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