searchMiddleIndex.js 449 B

1234567891011121314151617
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. function searchMiddleIndex(arr) {
  4. if (arr.length <= 1)
  5. return false;
  6. var first = 0;
  7. var last = arr.length - 1;
  8. while (first !== last && first + 1 !== last && last - 1 !== first) {
  9. first++;
  10. last--;
  11. }
  12. if (first === last) {
  13. return [--first, last];
  14. }
  15. return [first, last];
  16. }
  17. exports.default = searchMiddleIndex;