mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
merge: binarySearch (#884)
* required, optional param left-to-right approch in BS * base case return early to avoid nested if block * codes formated with standard.js
This commit is contained in:
@@ -7,26 +7,26 @@ describe('BinarySearch', () => {
|
||||
|
||||
it('should return index 3 for searchValue 10', () => {
|
||||
const searchValue = 10
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(3)
|
||||
expect(binarySearch(arr, searchValue, low, high)).toBe(3)
|
||||
})
|
||||
|
||||
it('should return index 0 for searchValue 2', () => {
|
||||
const searchValue = 2
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(0)
|
||||
expect(binarySearch(arr, searchValue, low, high)).toBe(0)
|
||||
})
|
||||
|
||||
it('should return index 13 for searchValue 999', () => {
|
||||
const searchValue = 999
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(13)
|
||||
expect(binarySearch(arr, searchValue, low, high)).toBe(13)
|
||||
})
|
||||
|
||||
it('should return -1 for searchValue 1', () => {
|
||||
const searchValue = 1
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(-1)
|
||||
expect(binarySearch(arr, searchValue, low, high)).toBe(-1)
|
||||
})
|
||||
|
||||
it('should return -1 for searchValue 1000', () => {
|
||||
const searchValue = 1000
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(-1)
|
||||
expect(binarySearch(arr, searchValue, low, high)).toBe(-1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user