题解 | #计数#

计数

https://www.nowcoder.com/practice/628339bd8e6e440590ad86caa7ac6849

统计数组 arr 中值等于 item 的元素出现的次数
输入:
[1, 2, 4, 4, 3, 4, 3], 4
复制
输出:
3

function count(arr, item) {
   let num = 0;
   let i = 0;
   while(i<arr.length){
       if(arr[i]==item){
           num++;
       }
       i++;
   }
    return num;
}
#计数j0#
全部评论

相关推荐

牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务