Home  >  Q&A  >  body text

javascript - 关于es6的算法问题

powersOfTwo(0) // [1]
powersOfTwo(1) //[1, 2]
powersOfTwo(4) // [1, 2, 4, 8, 16]


function powersOfTwo(n) {
  return Array.from({length: n + 1}, (v, k) => 2 ** k);
}

这里的2**k是怎么理解?

阿神阿神2723 days ago455

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-11 13:06:12

    es7 特性

    Exponentiation

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-11 13:06:12

    表示2的k次方

    reply
    0
  • Cancelreply