Last active
November 26, 2020 20:13
-
-
Save the-mgi/0e78ed7dd235e6e2441c60e05d023b27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function JumpSearchRecursive(array: number[], key: number): number { | |
| const jumpSize = Math.floor(Math.sqrt(array.length)); | |
| let val = jumpSize; | |
| const getHighLowRanges = () => { | |
| if ((array[val] > key) || (val >= array.length)) { | |
| return; | |
| } else { | |
| val = val + jumpSize; | |
| getHighLowRanges(); | |
| } | |
| }; | |
| getHighLowRanges(); | |
| let ansIndex = -1; | |
| val = val > array.length ? array.length : val; | |
| const iterateOverRange = (startIndex, lastIndex) => { | |
| if (startIndex >= lastIndex) { | |
| return -1; | |
| } else if (array[startIndex] === key) { | |
| return startIndex; | |
| } else { | |
| return iterateOverRange(startIndex + 1, lastIndex); | |
| } | |
| }; | |
| ansIndex = iterateOverRange(val - jumpSize, val); | |
| return ansIndex; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment