Alternative solution for "Missing Letters" algorithm

Alternative solution for "Missing Letters" algorithm


Hi. In working on an alternative solution to the “Missing Letters” challenge in the Intermediate Algorithm Scripting course, that is more intuitive to me, than the existing solutions. But it doesn’t work. Can you tell me why?
Here is my script:

  var alpha = 'abcdefghijklmnopqrstuvwxyz';
  alpha = Array.from(alpha);
  var output = [];
  for(let i = 0; i < str.length; i ++){
    var index = alpha.indexOf(str[i]);
    if(alpha[index] !== str[i])
  return output;    


I think these two lines create a kind of circular logic so that your if statement condition will never be true

var index = alpha.indexOf(str[i]); 
if (alpha[index] !== str[i])

For example, first iteration, first test case
In the case of str[i] = ‘a’
Find the index of a in the alphabet which is 0
Then test if alphabet[0] !== a

You might be able to tweak this to test if a letter was followed by the expected letter. Letter z could be a challenge.

Good to see that you are challenging the ‘accepted’ solution. :slight_smile:

ps If you wrap your code in triple backticks it will format nicely for the forum post ``` code inside ```