0
0
YYusifHasanov
The code creates an object called searchInsert that will hold the largest number found after inserting a number into an array. The code loops through the numbers in the numbers array, looking for the biggest number. If the target number is bigger than the number in the i position, then the code increments the i position, increments the biggest number, and returns the i value.
const searchInsert = (nums, target) => {
let biggest = 0;
for (let i = 0; i < nums.length; i++) {
if (target > nums[i]) {
biggest = i + 1;
}
if (target === nums[i]) {
return i;
}
}
return biggest;
};