DEV Community

Discussion on: I need help on this: cant get it to work.

Collapse
 
benjioe profile image
Benjioe • Edited

Probably that :

function binarySearch(list, target) {
    if (list.length === 0) {
        return false;
    }

    let midpoint = Math.floor(list.length / 2);
    if (list[midpoint] === target) {
        return true;
    }

    const left = list.slice(midpoint -1);
    const right = list.slice(midpoint +1, list.length);

    return binarySearch(right, target) || binarySearch(left, target);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
millidavitti profile image
millidavitti

Thank you for your response. I really appreciate the help