Skip to content

Instantly share code, notes, and snippets.

@rfprod
Last active April 22, 2017 16:00
Show Gist options
  • Save rfprod/909c4df7334592259ee4 to your computer and use it in GitHub Desktop.
Save rfprod/909c4df7334592259ee4 to your computer and use it in GitHub Desktop.
Missing Letters
function missingLetters(str) {
var seq = "abcdefghijklmnopqrstuvwxyz";
var firstEntry = seq.indexOf(str[0]);
var missing = "";
var missingCounter = 0;
var j = 1;
for (var i=firstEntry+1;i<firstEntry+str.length;i++){
if (str.charCodeAt(j) != seq.charCodeAt(i+missingCounter)){
missing = missing.concat(seq[i+missingCounter]);
missingCounter = missingCounter+1;
}
j = j+1;
}
if (missing === ""){
missing = undefined;
}
return missing;
}
missingLetters("bcd");

Missing Letters

Finds the missing letter in the passed letter range and returns it. If all letters are present in the range, returns undefined.

A script by V.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment