File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
lesson_07/conditionals/src Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ export function computeFactorial(n: number): number {
4343 * @return An array containing the first `n` Fibonacci values.
4444 */
4545export function getFirstNFibonacciNumbers ( n : number ) : number [ ] {
46+ if ( n < 0 ) {
47+ return [ ] ;
48+ }
4649 return [ ] ;
4750}
4851
@@ -74,5 +77,13 @@ export function binarySearch(
7477 // Else if values[pivotIndex] is greater than the value, then
7578 // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value;
7679 // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value.
80+
81+ if ( value === values [ pivotIndex ] ) {
82+ return pivotIndex ;
83+ } else if ( value < values [ pivotIndex ] ) {
84+ binarySearch ( values , start , pivotIndex - 1 , value ) ;
85+ } else {
86+ binarySearch ( values , pivotIndex + 1 , end , value ) ;
87+ }
7788 return - 1 ;
7889}
You can’t perform that action at this time.
0 commit comments