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:
Keramot UL Islam
2022-02-16 14:54:32 +06:00
committed by GitHub
parent c496925d25
commit 833d05d8d0
2 changed files with 20 additions and 22 deletions

View File

@@ -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)
})
})