编辑代码

function binarySearchDesc(arr, k) {
    let low = 0, high = arr.length - 1;
    while (low <= high) {
        let mid = Math.floor((low + high) / 2);
        if (arr[mid] === k) {
            return mid;
        } else if (arr[mid] > k) {
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    return -1;
}

// 测试代码
const arr = [85, 63, 52, 34, 25, 17, 6];
const k = 6;
const result = binarySearchDesc(arr, k);
console.log(result !== -1 ? `Element found at index: ${result}` : "Element not found");