File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -136,18 +136,17 @@ console.log(fibonacci(6)); // Output: 8
136
136
137
137
** Explanation** : Generates the nth Fibonacci number recursively by summing the two preceding numbers.
138
138
139
- <sup >[ Back to top] ( #algorithms ) </sup >
140
-
141
139
⚠️ ** Note** : This approach has exponential time complexity ` O(2^n) ` and is inefficient for large inputs.
142
140
141
+ <sup >[ Back to top] ( #algorithms ) </sup >
142
+
143
143
### Factorial of a Number
144
144
145
145
``` js
146
146
function factorial (n ) {
147
- if (n < 0 ) throw new RangeError ( ' Factorial is not defined for negative numbers ' );
148
-
147
+ if (n < 0 )
148
+ throw new RangeError ( " Factorial is not defined for negative numbers " );
149
149
if (n === 0 || n === 1 ) return 1 ;
150
-
151
150
return n * factorial (n - 1 );
152
151
}
153
152
You can’t perform that action at this time.
0 commit comments