Strings\words comparisons - advice needed

Hello everyone,

I need help to conceptually understand how to compare the following case:

Example:

  • Paragraph is given: “Hello Ladies and gentlemen, welcome to my example” .
  • User has to write the same sentence through input bar.

The first word the user types counts until user presses “Spacebar”.
Meaning, if user types Hellooooowe and hits space, the whole words is compared to the first word of the paragraph, i.e “Hello”.
Same for the rest, doesn’t matter how long the words is, it’s still compared to the next of order from pargarph.

My thoughts:

  • To store both the given text and user’s values in two arrays.
  • Whenever user press Space, the word he typed is added to array and compared with the text’s array. like
    userArray[2] === textArray[2].

There is something I can’t understand though,
whenever user hits “backspace” - he can edit the previous word. how?
Copy & Splice the last word from array?
and if user deletes the word as well, he can access the word before that as well.

Sorry for overly complex text

I am not quite sure what you are trying to accomplish, but why not just compare the whole string instead of each word in the string?

oh yeah, this is the stuff right here

I built a simple typing game with React that evaluates user’s WPM( Words Per Minute), and to make it more accurate I’d like to see when a user types a word and the word doesn’t match the on from the paragraph.

Additionally I want the user to be able to go back (backspace) and fix/edit what he wrote.

I’m essentially trying to imitate this behavior :

try the test and see