function count5numbers1(arr){
const m1 = arr.toString().match(/[5]/g);
if (typeof m1 === 'string' || m1 instanceof String){
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']));
I'm getting an answer is: [1,1,0,2,6,0,0]
But an expected answer is: [1,1,0,2,6,0, it's not a number]
Aucun commentaire:
Enregistrer un commentaire