Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This list showcases some of the most popular JavaScript algorithms, from simple string manipulations to classic recursive solutions and efficient searching techniques. Each snippet demonstrates a fundamental concept often encountered in coding interviews and real-world development.

> **Note:** Popularity is based on common interview topics, educational resources, and usage in developer communities.

## 1. Reverse a String

```js
Expand Down Expand Up @@ -46,7 +48,7 @@ console.log(binarySearch([1, 2, 3, 4, 5], 4)); // Output: 3

**Explanation**: Efficiently searches for a target in a sorted array using a divide-and-conquer approach.

## 4. Fibonacci Sequence
## 4. Fibonacci Sequence (Recursive)

```js
function fibonacci(n) {
Expand All @@ -59,6 +61,8 @@ console.log(fibonacci(6)); // Output: 8

**Explanation**: Generates the nth Fibonacci number recursively by summing the two preceding numbers.

⚠️ **Note**: This approach has **exponential time complexity O(2<sup>n</sup>)** and is inefficient for large inputs. Consider memoization or iteration for better performance.

## 5. Factorial of a Number

```js
Expand All @@ -82,6 +86,8 @@ function isPrime(num) {
}
return true;
}

console.log(isPrime(7)); // Output: true
```

**Explanation**: Checks if a number is prime by testing divisibility up to its square root.
Expand Down Expand Up @@ -152,4 +158,4 @@ function gcd(a, b) {
console.log(gcd(48, 18)); // Output: 6
```

**Explanation:** Uses the Euclidean algorithm to compute the greatest common divisor of two numbers.
**Explanation**: Uses the Euclidean algorithm to compute the greatest common divisor of two numbers.