I have a code that simply compares str2 (User input) with str1 (our reference string ) to check if any word in str2 is typed wrongly or correctly. The code works fine but I can't find a solution to this problem:
I want to ignore extra spaces, commas and dots and any other writing signs to be compared in both strings. just like a dictation app...
for example, below strings should assume as equal strings on output:
str1 = "I was sent to earth"
str2 = "I was, sent to: earth."
Any other modifications to improve this code is extremely appreciated. Please Help...
var str1 = "I was sent to earth to protect my cousin";
var str2 = "I waz Sent to earth to protet my cousine";
let a = str1.toLowerCase().split(' ');
let b = str2.toLowerCase().split(' ');
let res1 = b.filter(i => !a.includes(i));
let res2 = a.filter(i => !b.includes(i));
console.log(res1);
console.log(res2);
var str1 = res1.toString();
str1 = str1.replace(/,/g, '\n');
var str2 = res2.toString();
str2 = str2.replace(/,/g, '\n');
var player = GetPlayer();
player.SetVar("wrong_Spell",str1);
player.SetVar("right_Spell",str2);