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();
}
}