Last active
August 28, 2021 22:44
-
-
Save eday69/312a8662040190506c79e7ecde0fce45 to your computer and use it in GitHub Desktop.
freeCodeCamp Intermediate Algorithm Scripting: 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
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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,);