> maybe fill with incrementing number?
```js
Array.from({length: 6}, (_, i) => i)
```
> Are there use cases for filling with alternating values, as in `['x',
'y'].repeat(3)`?
Not so many, but for example when working with flat matrices,
`[0,0,255,1].repeat(len)` for generating quickly a uniform
Whatever the use cases might be, I like generators and spread for filling an
array with values, e.g.:
```jsfunction* repeat(n, ...values) { for (let i = 0; i < n; ++i) { yield*
values; }}
[...repeat(3, 'x', 'y')]
```
On Sunday, March 25, 2018, 3:41:10 PM CDT, Claude Pache
wrote:
OK, but your example wouldn't be acceptable in JavaScript, because it's
inconsistent with how `for(;;)` does initialization before the first `;`,
which is before iteration.
That's why I was saying that initializers-as-expressions simplifies doing
things like that, despite the other concerns.
On M
On Sun, Mar 25, 2018 at 9:20 PM, 月の影 <19511...@qq.com> wrote:
> Sometimes I got a infinity iterable sequences, I may want a partial spreed
> syntax. `...iterableObject{from, to}`
>
How would you prevent ambiguity between the spread and blocks?
iterable
{
from, to
};
is currently equivalent to
All of those seem like they would be worth adding. However, if they do get
added I think that since it would be so useful and it is very often requested a
`forEachInline` function would be a good addition. It would function exactly
like `forEach` except that the return value would be `this` inst
5 matches
Mail list logo