I have this function to compare to list in javaScript
function listCompare(list1, list2) {
let result = 0;
let final = (list1.length + list2.length) / 2;
for (let x of list1) {
for (let y of list2) {
if (x == y) {
result += 1;
}
}
}
return result / final * 100;
};
Its work just fine alone but when call it inside another function it return only zero. I don't know why this is the full code
function listCompare(list1, list2) {
let result = 0;
let final = (list1.length + list2.length) / 2;
for (let x of list1) {
for (let y of list2) {
if (x == y) {
result += 1;
}
}
}
return result / final * 100;
};
$('#id_password').change(function() {
// console.log('changed')
ls1 = time
ls2 = ob
var result = listCompare(ls1, ls2)
console.log(result)
if (result >= 70) {
$(':button[type="submit"]').prop('disabled', false);
}
});
note: I have two list one of them is time the author on is ob the function shode return the degree of matching between the two list and five to me
var test1 = [10,20,30,40,50,60,70,80];
var test2 = [10,20,30,40,50,60,70,80];
var test3 = [12,41,85,75,23,99,81,1236];
var test4 = [41,59,830,10,51,16,78,81];
console.log(listCompare(test1,test2))
output : 100
console.log(listCompare(test3,test4))
Output: 25
console.log(listCompare(test1,test4))
Output: 12.5