Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
