

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum of individual even and odd digits in a string number using JavaScript
Problem
We are required to write a JavaScript function that takes in string containing digits and our function should return true if the sum of even digits is greater than that of odd digits, false otherwise.
Example
Following is the code −
const num = '645457345'; const isEvenGreater = (str = '') => { let evenSum = 0; let oddSum = 0; for(let i = 0; i < str.length; i++){ const el = +str[i]; if(el % 2 === 0){ evenSum += el; }else{ oddSum += el; }; }; return evenSum > oddSum; }; console.log(isEvenGreater(num));
Output
false
- Related Questions & Answers
- Find the sum of digits of a number at even and odd places in C++
- Count odd and even digits in a number in PL/SQL
- Number Split into individual digits in JavaScript
- Difference between sums of odd and even digits.
- Find the Number With Even Sum of Digits using C++
- Number of even substrings in a string of digits in C++
- How to split JavaScript Number into individual digits?
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Prime digits sum of a number in JavaScript
- Check if product of digits of a number at even and odd places is equal in Python
- Determining sum of array as even or odd in JavaScript
- Separate odd and even in JavaScript
- Fetch Numbers with Even Number of Digits JavaScript
- Python program to find the sum of all even and odd digits of an integer list
- Splitting number to contain continuous odd or even number using JavaScript
Advertisements