Missing letters need Help!

Tell us what’s happening:
I have completed the test, but when referring to other ways, I have encountered a code that makes me difficult to understand.

Your code so far


// Adding this solution for the sake of avoiding using 'for' and 'while' loops.
// See the explanation for reference as to why. It's worth the effort.

function fearNotLetter(str) {
  var compare = str.charCodeAt(0), missing;

  str.split('').map(function(letter,index) {
    if (str.charCodeAt(index) == compare) {
      ++compare;
    } else {
      missing = String.fromCharCode(compare);
    }
  });

  return missing;
}

// test here
fearNotLetter("abce");

So, what is the function of “missing” in the following case:
var compare = str.charCodeAt(0), missing;
What is the difference when declaring variables in this way?

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

It’s more confusing, but it saves few characters and one line.
By most of the popular linters it’s considered bad practice.

1 Like

But i need to understand how it works, if you know, can you explain to me how it works? Thank you.

It’s the same as:

var compare = str.charCodeAt(0);
var missing;

First line assigns str.charCodeAt(0) to compare variable. Second line just declares missing variable.

1 Like

I got it, thank you very much !!!