Search Insert Position | LeetCode 35

[Written explanation will be added soon]

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard


Here is the full implementation.

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
let searchInsert = function(nums, target) {
    let index = 0;

    while (index < nums.length) {
      if (nums[index] === target || nums[index] > target) {
        return index;
      } else {
        index++;
      }
    }

    return index;
};