the replace function isnt working as a thought it would. came across this piece of code. i know the replace function is to replace all punctuation marks so as to not count them as letters. but when i log a string including punctuations it counts them as well. trying to figure out why
const getLetterCount = (stringToTest) => {
const wordArray = stringToTest.split('');
let totalLetters = 0;
for (let word of wordArray) {
word.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
totalLetters += word.length;
}
console.log(totalLetters);
}
getLetterCount('boy/girl?') // returns 9 ( counting punctuation as well)