I haven’t coded this, but I find it super clever, building a string containing all the different letters until the missing one and then finding a correspondence with match method.
However I don’t get str[0].charCodeAt(0)
, that’s a typo, right? Should be str.charCodeAt(0)
, right? Not sure why it’s not breaking the code actually.
Your code so far
function fearNotLetter(str) {
var allChars = "";
var notChars = new RegExp("[^" + str + "]", "g");
for (var i = 0; allChars[allChars.length - 1] !== str[str.length - 1]; i++)
allChars += String.fromCharCode(str[0].charCodeAt(0) + i);
return allChars.match(notChars)
? allChars.match(notChars).join("")
: undefined;
}
// test here
fearNotLetter("abce");
Challenge: Missing letters
Link to the challenge: