In my array object, I am comparing each string and incrementing the value if one letter does not match. If three characters match with the string, then I increase the count value; otherwise, it remains 0.
var obj = ["race", "sack", "grass", "brass", "beat", "pack", "cake"]
function getValue(obj) {
var count = 0
for (var i = 0; i <= obj.length; i++) {
for (var j = 1; j <= obj.length; j++) {
if (obj[i].split("") == obj[j].split("")) {
count++;
}
}
}
}
Expected Output
race 1
sack 2 // (pack, cake matches 3 letters with sack so 2)
grass 1
brass 1
beat 0
pack 2
cake 3