I wrote this function to remove punctuation. I tested everything and the problem seems to be the firstIndex variable failed to increase by 1 each loop.
I tried to increase the firstIndex by using Increment Operator but this variable only increase once only and reach max value at 1. I truly dont know to fix this
const textInput = "Hello world!"
const insensitiveText = textInput.toLocaleLowerCase();
const letters = insensitiveText.split("");
const removePunctuation = (letters) =>{
const tempArray = new Array();
for( const i in letters){
var firstIndex = 0;
if(letters[i].charCodeAt() > 96 && letters[i].charCodeAt() < 123){ // This loop succeeded in removePunctuation;
tempArray[firstIndex] = letters[i];
firstIndex = firstIndex + 1;
}
}
return(tempArray);
}
New contributor
Thành Hoàng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3