Lets say I have an array of numbers
let answerKey = ['0', '0', '1', '2', '2']
I want to test the number of repeats (number of instances) of each value
If the number of instances meets the requirement, then push that value to another array
let processKey = []
If the requirement = 2, and there are 2 instances of '0', processedKey.push(0)
What are some ways to tackle this?
I'ved tried
for(let prop in answerKey){
let counter = 0
answerKey.forEach(element => {
if (element === element) {
counter++;
}
});
if (counter == length){
processedKey.push(prop)
}
}