Compare user response with string using javascript for quizz


Compare user response with string using javascript for quizz



I have a input field for the user who's listening a music and try to find the correct artist or track name.


<input type="search" id="search" class="form-control form-control-lg" name="search" autocomplete="off" autofocus>



i would like to it compare with two javascript variables :



The problem is to handle human typing errors.
ex : "alicia key falin" should return true for the artist and the track name.



I have already tried scripts about Hamming Distance and also the fusejs library but i'm not convainced by the result.



Actual tests :


function hammingDistance(str1, str2) {
var dist = 0;
str1 = str1.toLowerCase();
str2 = str2.toLowerCase();
for (var i = 0, j = Math.max(str1.length, str2.length); i < j; i++) {
if (!str1[i] || !str2[i] || str1[i] !== str2[i]) {
dist++;
}
}
return dist;
}



The objective being to prevent capital, lower case, hyphen, period, comma, number, featuring, feat, etc. errors.



Is there some librairies or script to handle this properly?





Have you looked at regular expressions. They seem as if they would suit your needs.
– Jonathan Bartlett
Jul 2 at 10:36





@JonathanBartlett Regular expressions will work for special characters but for typos?
– mchev
Jul 2 at 11:10









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy