domenic at domenicdenicola.com (2014-03-02T22:44:28.614Z)
On Feb 24, 2014, at 4:18 PM, Claude Pache wrote:
> Personally, I consider that the impossibility to "yield a hole" must be considered as a feature, not a bug. Holes are useful in order to have consistent results for `Array.from([1, , 3])` (i.e., getting an exact copy), but their use should not be encouraged. (Note that, if you really want to, you can always (painfully) wrap a generator producing sentinel values with a hand-made iterable that forwards the results, transforming sentinel values into holes in the process.)
It easy enough to write an keys or entries iterator that ignores holes:
```js
function *sparseKeys(array) {
for (indx of array.keys()) if (Object.hasOwnProperty(array, key)) yield indx;
}
function *sparseEntries(array) {
for (entry of array.entries()) if (Object.hasOwnProperty(array, entry[0])) yield entry;
}
```
The same thing could be done for values but that seems less useful.
On Feb 24, 2014, at 4:18 PM, Claude Pache wrote: > > Personally, I consider that the impossibility to "yield a hole" must be considered as a feature, not a bug. Holes are useful in order to have consistent results for `Array.from([1, , 3])` (i.e., getting an exact copy), but their use should not be encouraged. (Note that, if you really want to, you can always (painfully) wrap a generator producing sentinel values with a hand-made iterable that forwards the results, transforming sentinel values into holes in the process.) It easy enough to write an keys or entries iterator that ignores holes: function *sparseKeys(array) { for (indx of array.keys()) if (Object.hasOwnProperty(array, key)) yield indx; } function *sparseEntries(array) { for (entry of array.entries()) if (Object.hasOwnProperty(array, entry[0])) yield entry; } The same thing could be done for values but that seems less useful. Allen