Why is using a generator function slower than filling and iterating an array in this example?

后端 未结 4 1486
温柔的废话
温柔的废话 2021-02-12 21:26

A Tale of Two Functions

I have one function that fills an array up to a specified value:

function getNumberArray(maxValue) {
    const a         


        
4条回答
  •  北海茫月
    2021-02-12 21:34

    Try replacing the 'let' in the generator function with a function scoped 'var'. It seems that the 'let' inside the loop incurs a lot of overhead. Only use let if you absolutely have to.

提交回复
热议问题