At the entrance comes the word, for example:

var name = "космос"; 

And there is the right word:

 var result = "космос"; 

It is necessary if the name == result returns true, but consider such options: name = "козмос/космоз/космас" and so on. How can this be done? That is, you need to remove such typos when voice dialing.

  • one
    Wow task) If there is a dictionary of possible words and a valid number of erroneous letters, then with some probability you can calculate a match. But with a few similar words in the dictionary possible false positives. In general, this is not an easy task. If you need a result close to 99% in a large dictionary, then you probably need a neuron to analyze the text semantically) - Mike Papou

1 answer 1

As an option

 function equals(word1, word2) { var ERR_LEVEL = 1; var arrWord1 = word1.split(''); var arrWord2 = word2.split(''); if (arrWord1.length !== arrWord2.length) { return false; } var currentErrorLevel = 0; for (var i = 0; i < arrWord1.length; i++) { arrWord1[i] !== arrWord2[i] && currentErrorLevel++; } return currentErrorLevel <= ERR_LEVEL; } 

Here ERR_LEVEL is the level of equality, in this case there may be a difference in one letter

  • Woo , thanks a lot) - IvanZ