SOURCE

function getNarcissisticNumbers(n) {
    
    // write your code here
    var max = Math.pow(10, n) - 1;
    var arr = []
    var min;
    if (n === 1) {
        min = 0
    } else {
        min = Math.pow(10, n - 1)
    }
    var value = min;
    if (n === 1) {
        // 测试其他使用
        getNarcissisticNumbers(4)
    }
    console.log(min, max)
    while(true) {
        if (value > max) {
            break
        }
        if ( value === splitAndPower(value)) {
            arr.push(value)
        }
        value += 1
    }
    console.log(arr)
    return arr
  }

  let splitAndPower = (number)=>{
    var numString = number.toString()
    var power = numString.length
    var i = 0
    var sum = 0
    while(true){
        if(i>power-1){
            break
        }
        var value = Math.pow(Number(numString[i]),power)
        sum += value
        i++
    }
    return sum
}

getNarcissisticNumbers(3)
console 命令行工具 X clear

                    
>
console