Intermediate Algorithm Scripting - Missing letters

Tell us what’s happening:
Hi, I think I am close to solve this challenge but am stuck. I checked the advance solutions but want to know if it is possible to solve it without using regular expression but by using something similar to my code below.
(Excuse me for my repetitive code. I am in progress to write neat one.)

Thank you so much in advance.

Your code so far

function fearNotLetter(str) {
  const complete = "abcdefghijklmnopqrstuvwxyz".split("");
  const start = str[0];
  const end = str[str.length-1];
  const startingIndex = complete.findIndex((ele) => ele === start);
  const endIndex = complete.findIndex((ele)=> ele === end);

  const pickingAlphabets = complete.splice(startingIndex,endIndex+1 );

let result;
  for(let j=0;j< str.length; j++){
    if(pickingAlphabets[j]!== str[j]){
      return result = pickingAlphabets[j];
    } else if(pickingAlphabets[j]=== str[j]){
      return result = undefined
    }
   return result; //I am not sure what to return...

  } 

}


fearNotLetter("abce");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Missing letters

Link to the challenge:

Yes you don’t need regex to solve this problem.

Your code has several redundancies and one obvious error.

The logic error is here.
In the else statement.
You can find it yourself if you add some console.log statements to show you exactly when the else if statement will trigger

  for(let j=0;j< str.length; j++){
    console.log(str[j]);
    if(pickingAlphabets[j]!== str[j]){
      return result = pickingAlphabets[j];
    } else if(pickingAlphabets[j]=== str[j]){
        console.log(pickingAlphabets[j]);
      return result = undefined
    }
   return result; //I am not sure what to return...

  } 

Something like above should give you interesting information.

Thank you so much for replying to my question! It was really helpful.

I checked my code today and understood that my logic was completely wrong. I also had hard time trying to figure out a way to solve this without using charCodeAt() and fromCharCode() methods. But anyway, I am happy that I got to learn new methods here.

Thank you!

1 Like