Hackernoon logoThe Magic of Iterators: Build Python range() in JavaScript by@guyariely

The Magic of Iterators: Build Python range() in JavaScript

Python range() refers to the use of the range type to create an immutable sequence of numbers. The range() constructor has two forms of definition: range(stop) and range(start, stop[, step) The Python examples above wrap the return value of range with list(). An equal example in JavaScript should probably look something like this: Array.from(range(1, 11) The result is a simple one-liner: Array(stop - start).fill(start).map((el, i) => el + i)
image
Guy Ariely Hacker Noon profile picture

@guyarielyGuy Ariely

Web Developer and Computer Science student 👨🏻‍💻

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.