# Spot the bug - #20

**URL:** <https://forum.kirupa.com/t/spot-the-bug-20/681024>\
**Category:** web dev\
**Created:** [April 30, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-20/681024 "2026-04-30T07:00:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [April 30, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-20/681024/1 "2026-04-30T07:00:08Z")

</div>

This one is intentionally tricky.

```js
function range(start, end) {
  return {
    [Symbol.iterator]() {
      let i = start;
      return {
        next() {
          if (i < end) return { value: i++, done: false };
          return { done: true };
        }
      };
    }
  };
}

const iter = range(1, 4)[Symbol.iterator]();
const arr = [...iter];
console.log(arr.join(','));

```

Reply with what is broken and how you would fix it.

WaffleFries

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [April 30, 2026, 7:49am UTC](https://forum.kirupa.com/t/spot-the-bug-20/681024/2 "2026-04-30T07:49:36Z")

</div>

What’s broken is `iter` isn’t iterable. You grabbed the iterator object (`{ next() { … } }`), but it doesn’t have a `[Symbol. iterator]()` method, so `[. . . iter]` blows up. Fix is either spread the iterable: `const arr = [. . . range(1, 4)]; ` or make the iterator return itself:

```auto
const iter = range(1, 4)[Symbol.iterator]();
iter[Symbol.iterator] = () => iter;
const arr = [...iter];

```

I found a related kirupa. com article that can help you go deeper into this topic:
