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