This solution is generated by ChatGPT, correctness is not guaranteed.
AI solution for JavaScript Coding Question on BFE.dev
49. search last index with Binary Search(possible duplicate array)
/**
* @param {number[]} arr - ascending order array with possible duplicates
* @param {number} target
* @returns {number} - last index of target number in arr, -1 if not found
*/
function binarySearchLast(arr, target) {
// your code here
}
Example:
const arr = [1,2,2,2,3,3,4,5,6];
console.log(binarySearchLast(arr, 2)); // 3
console.log(binarySearchLast(arr, 3)); // 5
console.log(binarySearchLast(arr, 6)); // 8
console.log(binarySearchLast(arr, 0)); // -1