Created
September 14, 2015 00:28
-
-
Save pavelnganpi/771da21e115a9ae88452 to your computer and use it in GitHub Desktop.
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
var get_missing_letters = function (str) { | |
var alphabets = new Array(26); | |
var missing = []; | |
//initialize data | |
for (var j = 0; j < alphabets.length; j++) { | |
alphabets[j] = 0; | |
} | |
//increases the frequency of a character | |
for (var i = 0; i < str.length; i++) { | |
var character = str.charAt(i).toLowerCase(); | |
if (isLetter(character)) { | |
alphabets[character.charCodeAt(0) - 97] += 1; | |
} | |
} | |
//look for any characters with frequency 0. If there are any, | |
//then it is a missing character | |
for (var k = 0; k < alphabets.length; k++) { | |
if (alphabets[k] === 0) { | |
var asciiCode = k + 97; | |
missing.push(String.fromCharCode(asciiCode)); | |
} | |
} | |
return missing.join(""); | |
}; | |
function isLetter(character) { | |
var asciiValue = character.charCodeAt(0); | |
if ((asciiValue >= 65 && asciiValue <= 90) || (asciiValue >= 97 && asciiValue <= 122)) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment