Skip to content

Commit d5f5be4

Browse files
committed
Recursion source code & videos added
1 parent 0aa9ebe commit d5f5be4

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
- [Time Complexity: Big O notation](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Time%20Complexity/README.md)
2727
- [Array](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Array/README.md)
2828
- [Polyfill of Map, Filter & Reduce](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Array/Polyfill.md)
29-
- [String](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/String/README.md)
29+
- [String](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/String/README.md)
30+
- [Recursion](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Recursion/README.md)

Recursion/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Recursion in JavaScript
2+
3+
<p align="center">
4+
<a href="https://youtu.be/5J07qXtAPb4">
5+
<img src="https://img.youtube.com/vi/5J07qXtAPb4/0.jpg" alt="Recursion in JavaScript" />
6+
</a>
7+
</p>
8+
9+
### Factorial of a Number
10+
11+
```javascript
12+
function factorial(n){
13+
if(n === 0)
14+
return 1;
15+
return n * factorial(n - 1);
16+
}
17+
18+
console.log(factorial(8));
19+
```
20+
21+
### Sum of Array
22+
23+
```javascript
24+
function sumOfArrays(arr, n){
25+
if(n === 0){
26+
return 0;
27+
}
28+
29+
return arr[n - 1] + sumOfArrays(arr, n - 1);
30+
}
31+
32+
console.log(sumOfArrays([1, 2, 3, 4, 5], 5));
33+
```
34+
35+
### Fibonacci Number
36+
37+
```javascript
38+
function fibo(n){
39+
if(n < 2){
40+
return n;
41+
}
42+
return fibo(n - 1) + fibo(n - 2);
43+
}
44+
45+
console.log(fibo(5));
46+
```
47+
48+
### Practice Questions (solve using recursion):
49+
50+
- Check whether a string is palindrome or not
51+
- Create pow(x, n) function which returns x^n
52+
- Create a function which returns the sum of digits of a number (e.g., sumOfDigits(453) is 12)
53+
- Create a function which returns the number of digits in a number (e.g., countDigits(453) is 3)
54+
- Create a function to find the LCM of two numbers
55+
- Create a function to find the GCD of two numbers
56+
- Create a function to reverse a string

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy