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 {
43
43
* @return An array containing the first `n` Fibonacci values.
44
44
*/
45
45
export function getFirstNFibonacciNumbers ( n : number ) : number [ ] {
46
+ if ( n < 0 ) {
47
+ return [ ] ;
48
+ }
46
49
return [ ] ;
47
50
}
48
51
@@ -74,5 +77,13 @@ export function binarySearch(
74
77
// Else if values[pivotIndex] is greater than the value, then
75
78
// call `binarySearch(values, start, pivotIndex - 1, value)` and return its value;
76
79
// 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
+ }
77
88
return - 1 ;
78
89
}
You can’t perform that action at this time.
0 commit comments