text: /* eslint-disable no-else-return */
  /**
   * Given a sorted array, find the index of the element with the given value.
   * Time complexity should be O(logN)
   *
   * @param {Array} array
   * @param {Number} value
   * @return {Number}
   *
   * @example
   * For ([1, 2, 3], 1) should return 0
   * For ([1, 2, 3], 2) should return 1
   *
   */
  function findIndex(arr, val) {
    let firstIndex = 0;
    let lastIndex = arr.length - 1;
    let mid = (firstIndex + lastIndex) / 2;
    while (firstIndex <= lastIndex) {
      mid = Math.floor((firstIndex + lastIndex) / 2);
      if (arr[mid] === val) {
        return mid;
      } else if (arr[mid] < val) {
        firstIndex = mid + 1;
      } else if (arr[mid] > val) {
        lastIndex = mid - 1;
      }
    }
    return -1;
  }
  
  module.exports = findIndex;
  