zoukankan      html  css  js  c++  java
  • 水仙花数[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]
  • 相关阅读:
    poj 2251
    poj 1321
    poj 2777
    poj 3468
    poj 2318
    javascript
    buhui
    swift 构造器
    mac上不了网
    字体
  • 原文地址:https://www.cnblogs.com/chentingjun/p/10543294.html
Copyright © 2011-2022 走看看