Help With "Missing Letters" Challenge Please *SOLVED*

Here’s my code so far:

function fearNotLetter(str) {
  let refStr = "abcdefghijklmnopqrstuvwxyz"; // Reference of the alphabet
  if (str === refStr) { // Checking that str isn't a full range
    return undefined;
  } else {
    let index = refStr.indexOf(str.charAt(0)); // Where to start cutting the reference
    let reducedRef = refStr.slice(index, str.length + 1); // str but complete
    return reducedRef.split("").filter(x => !str.includes(x)).join(); 
    // ^^^ Where I believe the issue is, but can't spot ^^^ :(
  }
}

/* 
Why is only one test failing, and why is it failing? (fearNotLetter("stvwx") specifically)
*/

It only fails the test “fearNotLetter(“stvwx”)”, but I have no idea why.

^^^ Here’s a picture of the failed test ^^^

Thanks in advance!

*Edit

I found the bug in my code, I solved it by specifying the index at which to stop cutting the reference. Thanks for all the help guys!

Updated Code:

  let refStr = "abcdefghijklmnopqrstuvwxyz"; // Reference of the alphabet
  if (str === refStr) { // Checking that str isn't a full range
    return undefined;
  } else {
    let beginIndex = refStr.indexOf(str.charAt(0)); // Where to start cutting the reference
    let endIndex = refStr.indexOf(str.charAt(str.length - 1)); // Where to stop cutting the reference
    let reducedRef = refStr.slice(beginIndex, endIndex); // str but complete
    return reducedRef.split("").filter(x => !str.includes(x)).join(); 
  }
}

What is the output when you run that test case? I think that is a very helpful hint if you run that test case manually.

Hey Jeremy, sorry for the late reply, but the failed challenge returns an empty string, “”.

image
^^^ Here’s the result (on CodePen.io) ^^^

and what should it return?

I just realized I typed the test wrong on CodePen :man_facepalming:.

image
^^^Here’s the test I meant to do, it should return the string “u” because that’s the missing letter in the range.

and the other one what should return?
because that too gives the wrong output

I doubt that the other one (fearNotLetter(“stuvwx”)) is even part of the challenge, as the only “full range” provided in the tests is the entire alphabet. Therefore, I don’t believe the code needs to account for “stuvwx” as an input.

Technically, “stuvw” is a perfectly valid input that should return undefined.

You are getting an empty string. So your filter has to be returning an empty array. So why is your filter returning an empty array?

Thanks for the help, I’ve soled the issue.

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