水仙花数[js]

 1 const getNarcissisticNumbers = function (n) {
 2     let min = Math.pow(10, n - 1) - 1
 3     let max = Math.pow(10, n)
 4     let res = []
 5     for (let i = min; i < max; i++) {
 6         let arr = (i + '').split('')
 7         let sum = 0
 8         for (let j = 0; j < arr.length; j++) {
 9             sum += Math.pow(arr[j], n)
10         }
11         if (sum === i) {
12             res.push(i)
13         }
14     }
15     return res
16 }
17 getNarcissisticNumbers(1)
18 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
原文地址:https://www.cnblogs.com/chentingjun/p/10543294.html