Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Iterate the iteratable object from the iterator object
function range(min, max) { return { // Return an object representing a range. get min() { return min; }, // The range's bounds are immutable. get max() { return max; }, // and stored in the closure. includes: function (x) { // Ranges can test for membership. return min <= x && x <= max; }, toString: function () { // Ranges have a string representation. return "[" + min + "," + max + "]"; }, __iterator__: function () { // The integers in a range are iterable. let val = Math.ceil(min); // Store current position in closure. return { // Return an iterator object. next: function () { // Return next integer in the range. if (val > max) // If we're past the end then stop. throw StopIteration; return val++; // Otherwise return next and increment. } }; } }; } // Here's how we can iterate over a range: //debugger; for (let i in range(1, 10)) print(i); // Prints numbers from 1 to 10
run
|
edit
|
history
|
help
0
David Anderson code challenge
1
js
JS exam part 2 - Find the property
Add more strength to input color
2-D Kinematics with accurate air drag
H
fratrade
Conditionals
Time Waister