ValleyBottomBinarySearch
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