HasEvenNumber

HasEvenNumber

Even numbers are whole numbers that cannot be divided exactly into pairs. Odd numbers, when divided by 2, leave a remainder of 0. Even numbers have the digits 2, 4, 6, 8 in their ones place.

Example:
console.log(hasEvenNumber([1,2,4,5])); true
console.log(hasEvenNumber([1,3,5])); false

function hasEvenNumber(arr){
  return arr.some(function(val){
    return val % 2 === 0;
  })
}

let arr= [1,2,3,4,5,6,7,8,9,10];
console.log(hasOddNumber(arr)); true


We create a function called hasEvenNumber with parameter called arr

We return the arr.some some is build in JavaScript method that only one needs to be true from the array;

We return arr.some(function(val){
return val % 2 === 0})
This means that we take the arr argument use the some method and iterate and check if val % (remainder operator) 2 is equal to remainder 0;


comments powered by Disqus