Javascript 使用数组元素和数组字符串查找重复的元素计数

Javascript 使用数组元素和数组字符串查找重复的元素计数,javascript,arrays,function,if-statement,match,Javascript,Arrays,Function,If Statement,Match,我在一个函数中传递数组元素和数组字符串,并将其转换为字符串,然后查找重复的元素计数 函数count5numbers1(arr,arr1){ 设m1=arr.toString().match(/[5]/gi); 让m2=arr1.toString().match(/[5]/gi); 如果(m1==null&&m2!=null){ 返回m1=0; }否则如果(m1!=null){ 返回m1.length; }else if(m2==null){ return m2=“它不是一个数字”; }否则{

我在一个函数中传递数组元素和数组字符串,并将其转换为字符串,然后查找重复的元素计数

函数count5numbers1(arr,arr1){
设m1=arr.toString().match(/[5]/gi);
让m2=arr1.toString().match(/[5]/gi);
如果(m1==null&&m2!=null){
返回m1=0;
}否则如果(m1!=null){
返回m1.length;
}else if(m2==null){
return m2=“它不是一个数字”;
}否则{
返回m2.length;
}
}
log(count5numbers1([1,2,5,43],[5]);
log(count5numbers1([1,2,3,5],[5]);
log(count5numbers1([1,2,4,2],[5]);
log(count5numbers1([2,4,54,15],[5]);
log(count5numbers1([1,5,55555],[5]);
log(count5numbers1([6,3,2,1],[5]);

log(count5numbers1(['notnumber,它是一个字符串'],[])查找重复项的标准是什么,它完全依赖于m2。是的,但我只需要传递m1参数(arr)即可获得相同的结果,不需要m2和arr1(参数)
function count5numbers1(arr) {
  const m1 = arr.toString().match(/[5]/g);
  if (arr.some(e => typeof e != 'number')) {
    return "it's not a number";
  } else if (m1 === null) {
    return 0;
  } else {
    return m1.length;
  }
}

console.log(count5numbers1([1, 2, 5, 43]));
console.log(count5numbers1([1, 2, 3, 5]));
console.log(count5numbers1([1, 2, 4, 2]));
console.log(count5numbers1([2, 4, 54, 15]));
console.log(count5numbers1([1, 5, 55, 555]));
console.log(count5numbers1([6, 3, 2, 1]));
console.log(count5numbers1(['notnumber,its a string']));