// In this problem, solve a famous programming interview question to find the index of the last occurrences of a number
// in a sorted array using binary search in O(log n) time.

// ex. input
// [1,2,2,2,2,3,4,5,5,5,5,6,6,7] 2
// [1,2,2,2,2,3,4,5,5,5,5,6,6,7] 8
// [1,2,2,2,2,3,4,5,5,5,5,6,6,7] 5

// ex. output
// 4
// -1
// 10

/**
 * @param {array[], number} nums k
 * @return {number}
 */

function findLast(nums, k){
    var low = 0,
        high = nums.length -1,
        result = -1,
        mid;

    while( low<=high ){
        mid = Math.floor( (low+high)/2 );

        if( nums[mid] === k ){
          result = mid;
          low = mid + 1; // go on searching higher indices (towards right)
        } else if( k < nums[mid]){
          high = mid-1
        } else {
          low = mid+1
        }
  }
  return result;
}

console.log(findLast([1,2,2,2,2,3,4,5,5,5,5,6,6,7], 5))

@@ -388,16 +388,719 @@
 r%7D%0A */%0A%0A
+// create a function that performs a binary search until item is found and increments index until last occurence is found%0A// set lowest index, and highest index variables%0A// set result to -1 in case no occurence is found%0A// create a while that breaks once lowest idnex meets highest index%0A  // create a mid variable by adding index's and dividing by 2%0A  // if current mid element is equal to our item we increment up the array%0A  // if the current mid element is greater than the item%0A    // we reset our high index to the element before our mid element%0A  // if the current mid element is less than the item%0A    // we reset our low index to the element after our mid element%0A// return result at the end%0A%0A
 function
@@ -1225,16 +1225,58 @@
 =high )%7B
+ // once low meets high index, loops stops
 %0A       

add logic