.filter() returns empty array [Intermediate Algorithm Scripting: Missing letters]

Hi! I’m trying to complete the _Intermediate Algorithm Scripting: Missing letters. This is the code i wrote.

I thought that negating the condition inside .filter() would have done the magic, but it returns me an empty array.

Am i completely wrong in my approach, so i can’t use filter this time, or am i close to the solution? Any hint?

function fearNotLetter(str) {
  const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); 
  const userStr = str.split('').sort();

  //Find first and last chars of argument string
  const strStart = userStr[0];
  const strEnd = userStr[userStr.length-1];

  //Split alphabet array to match argument string chars
  const alphabetStart = alphabet.indexOf(strStart);
  const alphabetEnd = alphabet.indexOf(strEnd);
  const alphabetChunck = alphabet.slice(alphabetStart, alphabetEnd+1);
  return str = userStr.filter( item => !alphabetChunck.includes(item) );

const test1 = fearNotLetter("abce");

Firstly, you have an assignment in a return statement, which is not what you want.

Secondly, I think you have your filtering backwards. You are removing letters from userStr that are not present in alphabetChunck. Isn’t userStr the one that is going to be missing letters?

1 Like