From 44b698d3f9783b20294b60b825960bc71b5a31fe Mon Sep 17 00:00:00 2001 From: Federico Fiaschi Date: Sun, 4 Aug 2024 22:02:36 +0200 Subject: [PATCH] fix : prettier fix --- search/exponential_search.ts | 67 +++++++++++++------------- search/test/exponential_search.test.ts | 8 +-- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/search/exponential_search.ts b/search/exponential_search.ts index 01c68051..0b1a2ddf 100644 --- a/search/exponential_search.ts +++ b/search/exponential_search.ts @@ -13,38 +13,37 @@ */ export const exponentialSearch = ( - array: number[], - x: number - ): number | null => { - const arrayLength = array.length; - if (arrayLength === 0) return null; - - if (array[0] === x) return 0; - - let i = 1; - while (i < arrayLength && array[i] <= x) { - i = i * 2; - } - - return binarySearch(array, x, i / 2, Math.min(i, arrayLength - 1)); - }; - - const binarySearch = ( - array: number[], - x: number, - start: number, - end: number - ): number | null => { - while (start <= end) { - const mid = Math.floor((start + end) / 2); - if (array[mid] === x) { - return mid; - } else if (array[mid] < x) { - start = mid + 1; - } else { - end = mid - 1; - } + array: number[], + x: number +): number | null => { + const arrayLength = array.length + if (arrayLength === 0) return null + + if (array[0] === x) return 0 + + let i = 1 + while (i < arrayLength && array[i] <= x) { + i = i * 2 + } + + return binarySearch(array, x, i / 2, Math.min(i, arrayLength - 1)) +} + +const binarySearch = ( + array: number[], + x: number, + start: number, + end: number +): number | null => { + while (start <= end) { + const mid = Math.floor((start + end) / 2) + if (array[mid] === x) { + return mid + } else if (array[mid] < x) { + start = mid + 1 + } else { + end = mid - 1 } - return null; - }; - \ No newline at end of file + } + return null +} diff --git a/search/test/exponential_search.test.ts b/search/test/exponential_search.test.ts index 8eaa5d75..80f6a07f 100644 --- a/search/test/exponential_search.test.ts +++ b/search/test/exponential_search.test.ts @@ -1,4 +1,4 @@ -import { exponentialSearch } from '../exponential_search'; +import { exponentialSearch } from '../exponential_search' describe('Exponential search', () => { test.each([ @@ -13,7 +13,7 @@ describe('Exponential search', () => { ])( 'of %o, searching for %o, expected %i', (array: number[], target: number, expected: number | null) => { - expect(exponentialSearch(array, target)).toBe(expected); + expect(exponentialSearch(array, target)).toBe(expected) } - ); -}); + ) +})