frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

141 - range - typescript

Open jsartisan opened this issue 1 year ago • 0 comments

index.ts

export const range = (from: number, to: number) => {
  return {
    [Symbol.iterator]() {
      return {
        current: from,
        last: to,

        next() {
          if (this.current <= this.last) {
            return { done: false, value: this.current++}
          } else {
            return { done: true }
          }
        }
      }
   }
  }
}

jsartisan avatar Aug 08 '24 14:08 jsartisan