I liked your recursive generator. How about something like this:
Number.prototype.to = function* (end) { const start = this; const step = end > start ? 1 : -1; const fn = function* (n) { let next = start + step * n; yield next; if (next === end) return; yield* fn(n + 1); }; yield start; yield* fn(1); } const asc = [...(1).to(5)]; const dsc = [...(5).to(1)]; console.log(asc); // [1, 2, 3, 4, 5] console.log(dsc); // [5, 4, 3, 2, 1]
Haha! I like this idea!
This is great, I wish this would make its way into the spec.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I liked your recursive generator. How about something like this:
Haha! I like this idea!
This is great, I wish this would make its way into the spec.