题目描述
统计数组 arr 中值等于 item 的元素出现的次数
示例1
输入
[1, 2, 4, 4, 3, 4, 3], 4
输出
3
代码
function count(arr, item) {
let count=0;
arr.forEach(element => {
if(element==item){
count++;
}
});
return count;
}
运行环境:JavaScript (V8 6.0.0)
运行时间:1041ms
占用内存:77888KB