for self development purposes I want to create a function with two parameters – string and an array. It should return a string without the letters given in the array.
function filterLetters(str, lettersToRemove) {
}
const str = filterLetters('Achievement unlocked', ['a', 'e']);
Could someone give me any pointers on how to achieve this?
>Solution :
For each letter to be replaced, replace it. When done, return the updated string:
function filterLetters(str, lettersToRemove) {
lettersToRemove.forEach(function(letter){
str = str.replaceAll(letter, '');
})
return str
}
Also see How to replace all occurrences of a string in JavaScript.