Question: Algorithm Challenge "Missing Letters" Solution

Continuing the discussion from freeCodeCamp Algorithm Challenge Guide: Missing Letters:

I have a question about this solution.
I cannot understand below line.
Variation “Compare” has two values? why there is comma(,) ?

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

It’s a shorthand for this:

var compare = str.charCodeAt(0);
var missing;
1 Like
function fearNotLetter(str) {
  let alpha = "abcdefghijklmnopqrstuvwxyz".split('');
  let missing = '';
  let i = alpha.indexOf(str[0]);
  let j = 0;
  for(; i < alpha.length; i++){
    if(alpha[i] !== str[j]){
      missing = alpha[i];
      return missing;
    }
    j++;
  }
  return;
}

fearNotLetter("abce");

my solution, not really optimal but easy to understand.

Here is my solution for the “Missing Letters” problem:

function fearNotLetter(str) {
  const letters = "abcdefghijklmnopqrstuvwxyz";
  const searchStr = letters.substring(letters.indexOf(str[0]), letters.indexOf(str[str.length - 1]));
  const result = searchStr.split('').filter(l => !str.includes(l));
  return result.length ? result.join() : undefined;
}
fearNotLetter("abce");
function fearNotLetter(str) {
  let alpha = 'abcdefghijklmnopqrstuvwxyz'
  let splitedAlpha = alpha.split("");
  let splitedString = str.split("");
  let strLen = str.length;
  let indexInAlpha = alpha.indexOf(str[0]);
  let returnedString = splitedAlpha.splice(indexInAlpha,strLen);
  
  for (let j=0; j<strLen; j++){
    if(splitedString[j]===returnedString[j]){
      continue;
    }
    else{
console.log(returnedString[j]);
      return returnedString[j];
    }
    

  }
  return undefined;
}

fearNotLetter("abcdefghijklmnopqrstuvwxyz");

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

I have blurred the spoiler solutions and set this thread to locked. Thanks for your understanding.

1 Like