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