-1

I need to write a function that returns a string without the characters 'a' and 's'. For example, the string 'SAverageSsA' will be returned by the function 'verge'. And the string 'AsaAAs' will return an empty string. How can i do this?

let testString = "AsSverage";

function removeAs(string) {}

removeAs(testString);
userName
  • 903
  • 2
  • 20
  • You don't need to write a function, just use `const string2 = testString.removeAll( /a|s/i, '' )`. That's it. – Dai Jul 09 '22 at 08:57

1 Answers1

1

You could convert the string to an array and filter the elements.

let testString = "AsSverage";

function removeAs(string) {
  return Array.from(string).filter((c)=>c!=='a'&&c!='A'&&c!='s'&&c!='S').join('')
}

console.log(removeAs(testString));
MWO
  • 2,627
  • 2
  • 10
  • 25