We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a327b68 commit 31344faCopy full SHA for 31344fa
README.md
@@ -84,8 +84,8 @@ a set of rules that precisely define a sequence of operations.
84
* `A` [Regular Expression Matching](src/algorithms/string/regular-expression-matching)
85
* **Searches**
86
* `B` [Linear Search](src/algorithms/search/linear-search)
87
- * `B` [Jump Search](src/algorithms/search/jump-search)
88
- * `B` [Binary Search](src/algorithms/search/binary-search)
+ * `B` [Jump Search](src/algorithms/search/jump-search) (or Block Search) - search in sorted array
+ * `B` [Binary Search](src/algorithms/search/binary-search) - search in sorted array
89
* **Sorting**
90
* `B` [Bubble Sort](src/algorithms/sorting/bubble-sort)
91
* `B` [Selection Sort](src/algorithms/sorting/selection-sort)
src/algorithms/search/jump-search/__test__/jumpSearch.test.js
@@ -17,4 +17,23 @@ describe('jumpSearch', () => {
17
expect(jumpSearch([1, 2, 5, 10, 20, 21, 24, 30, 48], 30)).toBe(7);
18
expect(jumpSearch([1, 2, 5, 10, 20, 21, 24, 30, 48], 48)).toBe(8);
19
});
20
+
21
+ it('should search object in sorted array', () => {
22
+ const sortedArrayOfObjects = [
23
+ { key: 1, value: 'value1' },
24
+ { key: 2, value: 'value2' },
25
+ { key: 3, value: 'value3' },
26
+ ];
27
28
+ const comparator = (a, b) => {
29
+ if (a.key === b.key) return 0;
30
+ return a.key < b.key ? -1 : 1;
31
+ };
32
33
+ expect(jumpSearch([], { key: 1 }, comparator)).toBe(-1);
34
+ expect(jumpSearch(sortedArrayOfObjects, { key: 4 }, comparator)).toBe(-1);
35
+ expect(jumpSearch(sortedArrayOfObjects, { key: 1 }, comparator)).toBe(0);
36
+ expect(jumpSearch(sortedArrayOfObjects, { key: 2 }, comparator)).toBe(1);
37
+ expect(jumpSearch(sortedArrayOfObjects, { key: 3 }, comparator)).toBe(2);
38
+ });
39
0 commit comments