Has A Zero
Has A Zero is number,array or string that include number 0 inside whether number , array or string.
Example:
console.log(hasAZero([1,2,3,4,5])) false
console.log(hasAZero([1,2,3,4,0])) true
console.log(hasAZero(“1202”)); true
console.log(hasAZero(“1222”)); false
function hasAZero(num){
return num.toString().split('').some(function(val){
return val === '0';
})
}
console.log(hasAZero([1,2,3,4,0]))
console.log(hasAZero([1,2,3,4,5]))
First we create function in our case hasAZero with only one parameter named num
We return num and convert it to string with .toString() method that converts everyting to string (numbers, strings and arrays).
After that we split the string with .split(‘’) method that converts the string into an array of strings.
Then we chain .some method that check if even one value of the converted array has 0 if it has at least one 0 it returns true, else false;
.some return callback function with parameter val and return val === ‘0’