I have to count the occurrence between two lists of strings. I need this function to complete my mastermind game. The problem is that I manage to count the occurrences but they are duplicated because of course you can't delete an element from a list by browsing it, otherwise, it's out of range.
These are made for the helper on the mastermind game of course.
Thanks for any help :)
Good day
I have for example :
answer = ["red","black","blue","green"]
playerHits = ["blue","blue","blue","black"]
The output should be a list like this :
helper = [null, null]
What i've tried and of course not working :
let cpPlay= [[null,null],[null,null],[null,null],[null,null]];
let cpAnswer= [[null,null],[null,null],[null,null],[null,null]];
for(let i = 0 ; i < play.length ; i++){
for(let j = 0 ; j < answer.length ; j++){
console.log(cpPlay.length);
console.log(cpAnswer.length);
if((cpPlay[i][0] === cpAnswer[j][0]) && (cpPlay[i][1] === cpAnswer[j][1])){
helper.push(true);
cpPlay = cpPlay.slice(i)
cpAnswer = cpAnswer.slice(j)
console.log('win')
}
else if((cpPlay[i][0] === cpAnswer[j][0]) && (cpPlay[i][1] !== cpAnswer[j][1])){
helper.push(null);
cpPlay = cpPlay.slice(i)
cpAnswer = cpAnswer.slice(j)
console.log('almost')
}
}
}