domenic at domenicdenicola.com (2014-03-02T22:44:42.783Z)
Indeed, but the question was about producing/forwarding holes rather than skip them, so that, e.g., `Array.from` could replace the elements at the correct positions.
Indeed, but the question was about producing/forwarding holes rather than skip them, so that, e.g., `Array.from` could replace the elements at the correct positions.
Le 25 févr. 2014 à 01:54, Allen Wirfs-Brock <allen at wirfs-brock.com> a écrit : > > 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 Indeed, but the question was about producing/forwarding holes rather than skip them, so that, e.g., `Array.from` could replace the elements at the correct positions. —Claude