'use strict';

function *circularIterator(arr) {
  let index = 0;
  const elements = Array.isArray(arr) ? arr.slice() : [];
  const length = elements.length;

  while (length) {
    yield elements[ index++ % length ];
  }
}

module.exports = circularIterator;

'use strict';

function *circularIterator(arr) {
  let index = -1;
  const elements = Array.isArray(arr) ? arr.slice() : [];
  const length = elements.length;

  while (length) {
    index = (index + 1) % length;
    console.log(index);
    yield elements[index];
  }
}

module.exports = circularIterator;

index now is always in array range, fix #17