I have a question that asked me to:
Clean the following text and find the most frequent word: "const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %te@a@ching%;. The@re $is no@th@ing; &as& mo@re rewarding as educa@ting &and& @emp%o@weri@ng peo@ple. ;I found tea@ching m%o@re interesting tha@n any ot#her %jo@bs. %Do@es thi%s mo@tiv#ate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of tea&ching'"
I used regEx to clean the string like this:
const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %te@a@ching%;. The@re $is no@th@ing; && mo@re rewarding than educa@ting &and& @emp%o@weri@ng peo@ple. ;I find tea@ching m%o@re interesting tha@n any ot#her %jo@bs. %Do@es thi%s mo@tiv#ate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of tea&ching';
const sentReg = /\W(?<!1)/g;
let sent = sentence.replace(/ /g, "1");
let finalSent = sent.replace(sentReg, ""), finalfinalSent = finalSent.replace(/1/g, " ");
I realized I don't know how to (or there might not be a way to) use the match() function to search a string by word, so I tried splitting it up into an array like:
let senArr = finalfinalSent.split(" "), wordOccur = [];
for (const x of senArr) {
var re = new RegExp(x, "g");
var y = finalfinalSent.match(re);
wordOccur = wordOccur.concat([y.length]);
};
... and now I'm stuck because I don't know how to search an array in JavaScript, only in Python, and I feel the way to search through a string would be much easier than this. I would appreciate some pointers.