I am working with an array that is continuously updated with new string elements every 2 seconds. The code snippet below showcases how the updates are processed:
//tick world
setInterval(function(){
doTradeUpdate();
},5000);
function doTradeUpdate(){
var randyManu = Math.floor(Math.random() * 10);
switch(randyManu){
case 0:
//new duro mine
countPush(manufacture,"duro-mine");
break;
case 1:
//new e-plant
countPush(manufacture,"e-plant");
break;
//etc
}
function countPush(arrayz,addable){
console.log(arrayz);
console.log("Attempting to add: " + addable);
if(arrayz.length == 0){
arrayz.push(addable);
}
else{
if (arrayz.indexOf(addable) > 0){
console.log("FOUND");
}
else{
console.log("NOT FOUND");
arrayz.push(addable);
}
}
}
However, an issue arises where sometimes the code outputs "FOUND" and other times "NOT FOUND" for the same array element, like "e-plant". Consequently, multiple duplicate entries can exist within the array. What could be causing this inconsistency in matching elements?
This script is solely responsible for handling the array updates.
Thank you!
G