Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2015 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/f36d1b6f70b88d7198be to your computer and use it in GitHub Desktop.
Save anonymous/f36d1b6f70b88d7198be to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: Missing letters
// Bonfire: Missing letters
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-missing-letters
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function fearNotLetter(str) {
// Create our variables.
var firstCharacter = str.charCodeAt(0);
var valueToReturn = '';
var secondCharacter = '';
// Function to find the missing letters
var addCharacters = function(a, b) {
while (a - 1 > b) {
b++;
valueToReturn += String.fromCharCode(b);
}
return valueToReturn;
};
// Check if letters are missing in between.
for (var index = 1; index < str.length; index++) {
secondCharacter = str.charCodeAt(index);
// Check if the diference in code is greater than one.
if (secondCharacter - firstCharacter > 1) {
// Call function to missing letters
addCharacters(secondCharacter, firstCharacter);
}
// Switch positions
firstCharacter = str.charCodeAt(index);
}
// Check whether to return undefined or the missing letters.
if (valueToReturn === '')
return undefined;
else
return valueToReturn;
}
fearNotLetter("abce");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment