Skip to content

Instantly share code, notes, and snippets.

@eday69
Last active August 28, 2021 22:44
Show Gist options
  • Save eday69/312a8662040190506c79e7ecde0fce45 to your computer and use it in GitHub Desktop.
Save eday69/312a8662040190506c79e7ecde0fce45 to your computer and use it in GitHub Desktop.
freeCodeCamp Intermediate Algorithm Scripting: Missing letters
// Find the missing letter in the passed letter range and return it.
// If all letters are present in the range, return undefined.
function fearNotLetter(str) {
let lastLetter=str.charCodeAt(0);
let missingLetter;
for (let i=1; i<str.length; i++) {
let currentLetter=str.charCodeAt(i);
console.log(lastLetter, currentLetter);
if ((lastLetter+1) < currentLetter) {
missingLetter = String.fromCharCode(currentLetter-1);
break;
}
else {
lastLetter=currentLetter;
}
}
return missingLetter;
}
fearNotLetter("abce");
@vlazic
Copy link

vlazic commented Aug 28, 2021

const fearNotLetter=(s,x="charCodeAt")=>s.split("").reduce((a,c,i)=>a?a:i&&c[x](0)-s[i-1][x](0)>1?String.fromCharCode(s[i-1][x](0)+1):undefined,0,);

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