

- 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
Check Disarium number - JavaScript
Disarium Number − All those numbers which satisfy the following equation are dDisarium number −
xy...z = x^1 + y^2 + ... + z^n
Where n is the number of digits in the number.
For example −
175 is a disarium number be: 175 = 1^1 + 7^2 + 5^3 = 1 + 49 + 125 = 175
Let’s write the code for this function −
Example
Following is the code −
const num = 175; const isDisarium = num => { const res = String(num) .split("") .reduce((acc, val, ind) => { acc += Math.pow(+val, ind+1); return acc; }, 0); return res === num; }; console.log(isDisarium(num)); console.log(isDisarium(32)); console.log(isDisarium(4334));
Output
The output in the console: −
true false false
- Related Questions & Answers
- Python program to check if the given number is a Disarium Number
- Disarium Number with examples in C++?
- Check for Ugly number in JavaScript
- Check for illegal number with isNaN() in JavaScript
- Check for a self-dividing number in JavaScript
- Check whether a number is a Fibonacci number or not JavaScript
- Check if input is a number or letter in JavaScript?
- Check if number falls in Fibonacci series or not - JavaScript
- Python program to print all Disarium numbers between 1 to 100
- How do you check that a number is NaN in JavaScript?
- How to check whether a value is a number in JavaScript?
- Check whether sum of digit of a number is Palindrome - JavaScript
- JavaScript: How to check if a number is NaN or finite?
- Parity Check of a Number
- How to check whether a number is finite or not in JavaScript?
Advertisements