Describing my attempt to create a function that processes string arrays by adding unique words to a word array, and incrementing the count of existing words in the count array:
var words = [];
var counts = [];
calculate([a, b]);
calculate([a, c]);
function calculate(result) {
for (var i = 0; i < result.length; i++) {
var check = 0;
for (var j = 0; i < tags.length; i++) {
if (result[i] == tags[j]) {
check = 1;
counts[i] = counts[i] + 20;
}
}
if (check == 0) {
tags.push(result[i]);
counts.push(20);
}
check = 0;
}
}
However, the actual output is:
words = a, b count = 2, 1
When I was expecting:
words = a, b, c count = 2, 1, 1
Your help is greatly appreciated!