DEV Community

Discussion on: Using Python range() in JavaScript

Collapse
 
ryands17 profile image
Ryan Dsouza

What's the difference b/w the above range function as opposed to this?

function* range(start, stop, step = 1) {
  if (stop === undefined) {
    stop = start
    start = 0
  }

  for (let i = start; i < stop; i += step) {
    yield i
  }
}
Enter fullscreen mode Exit fullscreen mode