Is there an easy way of comparing any two different size of string text to see how much percentage they're alike?
I'm trying this but I'm running into to this issue below. The left text area is the text to copy. The right is the user trying to copy the text ( in this example the user didn't get everything typed correctly, there's misspelled words and some words that the user forgot to type in).
After a countdown expires I try to calculate the percentage of how much the user correctly copied the given text in the left. And below on the left I have the text of the upper left text box put into an array using the split(" ") command on the text field. And the bottom right I do the same for the user entered text.
Before calculating how much percentage the user typed correctly I try to have a summation of how much words the user typed correctly as my code below shows:
for(var counter = 0; counter < userArr.length; counter++)
{
if(userArr[counter] === textArr[counter])
{
correct++;
}
}
At index 3 in the array the user mistyped something which is ok. But at index 6 the user completely missed typing a word. So that throws the rest of the indexes off by at least one to get the amount of words typed correctly. Without that I can't calculate the percentage typed correctly.
To me it seems I'd have to create a bunch of conditional checks within the for loop to account for that. But seems to be a bit messy.
So back to my original question, is there an easy way to so this calculations without creating a big mess of if statements? i.e. Is there an open source method, or built in javascript method to handle this?