lib/utility.js
function circulationSearch(array, current, direction, func) {
  let start = 0;
  let end = array.length - 1;
  if (direction === -1) {
    start = array.length - 1;
    end = 0;
  }

  for (let i = current; i * direction <= end * direction; i += direction) {
    if (func(array[i])) {
      return i;
    }
  }
  for (let i = start; i * direction < current * direction; i += direction) {
    if (func(array[i])) {
      return i;
    }
  }

  return -1;
}
function circulationSearch(array, current, direction, func) {
  let start = 0;
  let end = array.length - 1;
  if (direction === -1) {
    start = array.length - 1;
    end = 0;
  }

  for (let i = current; i * direction <= end * direction; i += direction) {
    if (func(array[i])) {
      return i;
    }
  }
  for (let i = start; i * direction < current * direction; i += direction) {
    if (func(array[i])) {
      return i;
    }
  }

  return -1;
}
function circulationSearch ( array , current , direction , func ) { let start = 0 ; let end = array . length - 1 ; if ( direction === - 1 ) { start = array . length - 1 ; end = 0 ; } for ( let i = current ; i * direction <= end * direction ; i += direction ) { if ( func ( array [ i ] ) ) { return i ; } } for ( let i = start ; i * direction < current * direction ; i += direction ) { if ( func ( array [ i ] ) ) { return i ; } } return - 1 ; }
direction 1, -1 need test
direction 1 - 1 need test