Checking Oddish and Evenish numbers - JavaScript



A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even.

We are required to write a function that determines whether a number is Oddish or Evenish. We should return true of Oddish values and false for evenish

Example

Following is the code −

const num = 434667; const isOddish = (num, sum = 0) => {    if(num){       return isOddish(Math.floor(num / 10), sum + (num % 10));    };    return sum % 2 === 1; }; console.log(isOddish(num));

Output

Following is the output in the console −

false
Updated on: 2020-09-16T09:49:52+05:30

264 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements