'use strict'

function *circularIterator(arr) {
  var index = 0,
    elements = Array.isArray(arr) ? arr.slice(0) : [],
    length = elements.length;
  while (true) {
    yield elements[index++ % length];
  }
}

module.exports = circularIterator;

'use strict';

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

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

module.exports = circularIterator;

change to es6 sintax