JavaScript Compare two string and display number of mismatching words from string

I know there are many techniques and methods to comparing two Strings, and find out if two Strings are equal or not. I want to do something like this:

Var Str1 = "Hello How are you?";
var Str2 = "Hello I am ravi.";

To compare str2 with str1 and display the number count of mismatching words. Both strings contain 4 words each. It should display you missed three words from str1.

I have one web page (web task) where a user needs to listen an audio and transcribe it. So I want to know how many words user misses from the transcribed original audio.

Answer:1

This is as simple as converting both the strings to an array and then computing the difference of arrays.

$arr1 = explode(' ', strtolower($str1));
$arr2 = explode(' ', strtolower($str2));
echo 'You missed ' . count(array_diff($arr1, $arr2)) . ' words from str 1';
Answer:2

Use explode to convert the Strings to Arrays and count the difference between the two Arrays:

$Str1 = "Hello How are you?";
$Str2 = "Hello I am ravi";

$st1 = (explode(" ", $Str1));
$st2 = (explode(" ", $Str2));


$result = array_diff($st1, $st2);

echo count($result);
Answer:3

Find and format difference between two strings in PHP

Try This : https://coderwall.com/p/3j2hxq/find-and-format-difference-between-two-strings-in-php

Answer:4

just wondering, what is the most efficient way to divide an array by a scalar? I can clearly loop over it, but efficiency is paramount in my case. common trivial way: var array_2 = [] var array_1 = ...

just wondering, what is the most efficient way to divide an array by a scalar? I can clearly loop over it, but efficiency is paramount in my case. common trivial way: var array_2 = [] var array_1 = ...

I have 2 types of a objects, a group, and an item. A group can have children which is either an array of groups or an array of items. I've ended up with a series of nested groups (which can be ...

I have 2 types of a objects, a group, and an item. A group can have children which is either an array of groups or an array of items. I've ended up with a series of nested groups (which can be ...

I want to get the values of all input at once using one .val() function in jQuery. $("#txt1").val(); $("#txt2").val(); $("#txt3").val(); Instead of this I want to write the below code $("#txt1, #...

I want to get the values of all input at once using one .val() function in jQuery. $("#txt1").val(); $("#txt2").val(); $("#txt3").val(); Instead of this I want to write the below code $("#txt1, #...

  1. multiple values input html
  2. multiple values input python
  3. multiple values input
  4. multiple values input angular
  5. multiple values input jquery
  6. multiple values in input field
  7. multiple values in input parameter
  8. pass multiple values input
  9. php multiple values input
  10. take multiple values input
  11. multiple values in one input field
  12. multiple values in hidden input
  13. multiple input values javascript

I have the sample code: var t = 20; function test () { console.log(t); var t = 100; } test(); The result will be undefined. I thought t was global variable, so why, when I log ...

I have the sample code: var t = 20; function test () { console.log(t); var t = 100; } test(); The result will be undefined. I thought t was global variable, so why, when I log ...

  1. this variable undefined javascript
  2. this variable is undefined mathcad
  3. this variable is undefined mathcad solve block
  4. this variable is undefined mathcad subscript
  5. this variable is undefined angular
  6. react this variable undefined
  7. php $this undefined variable
  8. this variable is undefined
  9. this variable is undefined маткад