количество повторений в массиве JavaScript
let targetted_array = [3,4,3,23,452,5,3,3,21,1,5,5];
function countInArray(array, element) {
let repeat_count = 0;
for (let i = 0; i < array.length; i++) {
if (array[i] === element) {
repeat_count++;
}
}
return repeat_count;
}
countInArray(targetted_array, 3) // will return 4. cuz "3" was repeated 4 times in the targetted_array
countInArray(targetted_array, 5) // will return 3. cuz "5" was repeated 3 times in the targetted_array
maldito codificador