text: /**
   * 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(array, value) {
    let first = 0;
    let last = array.length - 1;
    let index;
    let searchedElem;
  
    while (first <= last) {
      index = Math.floor((first + last) / 2);
      searchedElem = array[index];
  
      if (searchedElem === value) return index;
      if (searchedElem > value) {
        last = index - 1;
      } else {
        first = index + 1;
      }
    }
    return null;
  }
  
  module.exports = findIndex;
  