Code seems to work, but it's not accepted -missing letters

Tell us what’s happening:
Hi, I found my own solution to the challenge using slice() and a filter() at the end. Now, when I console.log the results, all the tests are fine…but when I switch to return the solution, I don’t pass a single test.
If I change the string manually for testing purposes, my solution works fine.
Can someone spot what’s wrong?

Your code so far

function fearNotLetter(str) {
const alphabet = [...'abcdefghijklmnopqrstuvwxyz']
let start = alphabet.indexOf(str[0])
let finish = alphabet.indexOf(str[str.length-1])
let arr1 = alphabet.slice(start, finish+1)
if (arr1 === str) {
  return undefined;
}
return arr1.filter(x=> str.indexOf(x) === -1)
}

fearNotLetter("abce");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36.

Challenge: Missing letters

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

You’re really close. Here’s the issue you’re encountering: when you compare arr1 to str, you’re comparing an array to a string. The same when you return arr at the end, you’re returning the array.

Do you remember how to convert that array of letters BACK into a string?

Thank you so much, I was getting cross-eyed and it was just a minimal error. I used the toString() and it worked.
Thanks again!!

1 Like