- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find even odd index digit difference - JavaScript
We are required to write a JavaScript function that takes in a number and returns the difference of the sums of the digits at even place and the digits odd place
Example
Let’s write the code −
const num = 345336; const evenOddDifference = (num, res = 0, ind = 0) => { if(num){ if(ind % 2 === 0){ res += num % 10; }else{ res -= num % 10; }; }; return Math.abs(res); }; console.log(evenOddDifference(num));
Output
Following is the output in the console −
2
- Related Articles
- Odd even index difference - JavaScript
- Even numbers at even index and odd numbers at odd index in C++
- Swapping even and odd index pairs internally in JavaScript
- Swap Even Index Elements And Odd Index Elements in Python
- Largest Even and Odd N-digit numbers in C++
- Separate odd and even in JavaScript
- Even index sum in JavaScript
- Identify in number 70169308, which digit is in odd and which digit is in even place?
- Adding only odd or even numbers JavaScript
- Odd even sort in an array - JavaScript
- Sorting odd and even elements separately JavaScript
- Difference between sums of odd and even digits.
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1 in C++
- JavaScript Sum odd indexed and even indexed elements separately and return their absolute difference

Advertisements