function * downToOne(n) { for (let i = n; i > 0; --i) { yield i; } } [...downToOne(5)] //=> [ 1, 2, 3, 4, 5 ] The array should be [5, 4, 3, 2, 1]