Quick actions

cmd+k|ctrl+k

Navigation

Languages

ValleyBottomBinarySearch

Snippet info

Language

JavaScript

Visibility

public

Author

ralletsfix

Created

2025-05-21T11:39:41.57113Z

Updated

2025-05-21T11:39:41.57113Z

const { valleyBottom } = require('./valleyBottom');

function runTests() {
    const tests = [
        // Example 1 from book
        [[6, 5, 4, 7, 9], 4],
        // Example 2 from book
        [[5, 6, 7], 5],
        // Example 3 from book
        [[7, 6, 5], 5],
        // Edge case - 2 elements
        [[2, 1], 1],
        // Edge case - 3 elements
        [[3, 2, 4], 2]
    ];
    
    console.log("START TESTS.");
    for (const [arr, want] of tests) {
        const got = valleyBottom(arr);
        console.assert(got === want,
            `\nvalleyBottom(${JSON.stringify(arr)}): got: ${got}, want: ${want}\n`);
    }
    console.log("END TESTS.");
}

runTests();
INFO