I just wrote the most horrible code ever, but it works - "Intermediate Algorithm Scripting - Missing letters"

I hope this doesn’t break any rules

function fearNotLetter(str) {

  let abc = "abcdefghijklmnopqrstuvwxyz";
  
  let start = abc.indexOf(str[0]);
  let j = 0;
  let junk = [];

  for (let i = start; i < str.length + start; i++){
    if(abc[i] !== str[j]){
      junk.push(str[j]);
    }
    j++;
  }

  return abc[abc.indexOf(junk[0])-1];
}

Challenge: Intermediate Algorithm Scripting - Missing letters

Link to the challenge:

The only rule is that the function does what the instructions ask for, and seeing as yours does, I’m not sure what rules it would break?

Yours could be cleaned up a little. I don’t think you need the junk array at all. In your for loop, when you find the first missing letter, can’t you just return then?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.