Intermediate Algorithm Scripting: Missing letters

Hi there!

I have a slight problem with this challenge. When I test it in my IDE I get perfectly fine results, but fcc doesn’t accept it all. Maybe you can have a look if I miss something or I just have a total wrong approach.

Thanks a lot!

function fearNotLetter(str) {
const abc = ‘abcdefghijklmnopqrstuvwxyz’;
const abcArr = abc.split("");

for (let i = 0; i < abcArr.length; i++)
if (!str.includes(abcArr[i])) {
return abc[i]
}
return undefined;
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters

I was going to say I think it’d fail too. If you are comfortable with regular expressions, you’ll have a much easier time imo.

Hi
I was just to redeem myself haha. My code expects the string to start from a!
Such a dumb mistake haha.
Thanks a lot anyway!

Yes. I just wanted to try something else. I just tested the first test and “undefined”.
I probably should go to bed haha.
Thanks mate!

If you think break will help, take it. Nothing is worse than looking at the screen with tired eyes.

Like the others, I’d expect your solution to not work either, as your approach makes some assumptions that aren’t always going to be the case.

I just attempted that challenge myself and the way I did it was basically by taking advantage of ASCII codes, as it’s generally easier to work with numbers than characters. Of course you can use RegEx too, as mentioned, but that’s generally sort of a quick-fix approach and probably not the approach that FCC wants you to take since RegExs don’t involve “algorithmic scripting”.

This is my solution, there are plenty of others that would work too:

function fearNotLetter(str) {
  let arr = str.split("");
  let ascii = arr.map(x => x.charCodeAt(0));
  for (let i = 1; i < ascii.length; i++) {
    if (ascii[i] > ascii[i-1] + 1) {
      return String.fromCharCode(ascii[i] - 1);
    }
  }
}

I rewrote my code and my solution was pretty similar. Actually straight forward and short!

function fearNotLetter(str) 
{
  let beginIndex = str.charAt(0).charCodeAt();

  for (let i=0; i < str.length; i++)
  {
    let expected = String.fromCharCode(beginIndex + i); 
    
    if (expected !== str[i])
    {
      return expected;
    }
  }

  return undefined;
}