Last active
October 25, 2017 14:28
-
-
Save danakt/edd8b1036095eea928b19ece4132cf2a to your computer and use it in GitHub Desktop.
Revisions
-
danakt revised this gist
Oct 25, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ Number.prototype[Symbol.iterator] = function* () { if (isNaN(this) || !isFinite(this)) { throw new ReferenceError('Non-iterable number') } const abs = Math.abs(this) -
danakt created this gist
Oct 25, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ Number.prototype[Symbol.iterator] = function* () { if (isNaN(this) || !isFinite(this)) { throw new Error('Non-iterable number') } const abs = Math.abs(this) const isNegative = this < 0 for (let i = 0; i < abs; i++) { yield isNegative ? -i : i } } [...10] // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for (let i of 5) { // ... }