Skip to content

Add 3 beginner JS problems: Palindrome, Fibonacci, Largest #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions 007 Palindrome Checker (L-B)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Palindrome Checker

Write a function that checks if a given string is a palindrome.
A palindrome is a word that reads the same backward as forward.

---

### Example:

Input: "racecar"
Output: true

Input: "hello"
Output: false


---

### Problem added by

[SaadQasim19](https://github.com/SaadQasim19)



### Solution

[Click here to see the solution](./solution.js)
15 changes: 15 additions & 0 deletions 007 Palindrome Checker (L-B)/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function isPalindrome(str) {
str = str.toLowerCase();
let i = 0, j = str.length - 1;
while (i < j) {
if (str[i] !== str[j]) return false;
i++;
j--;
}
return true;
}

// Test Cases
console.log(isPalindrome("racecar")); // true
console.log(isPalindrome("hello")); // false

28 changes: 28 additions & 0 deletions 008 Fibonacci Series (L-B)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Fibonacci Series

Write a function that returns the first `n` numbers of the Fibonacci sequence.
The Fibonacci sequence starts from 0 and 1, and each number is the sum of the two preceding ones.

---

### Example:

Input: 5
Output: [0, 1, 1, 2, 3]

Input: 8
Output: [0, 1, 1, 2, 3, 5, 8, 13]



---

### Problem added by

[SaadQasim19](https://github.com/SaadQasim19)

---

### Solution

[Click here to see the solution](./solution.js)
13 changes: 13 additions & 0 deletions 008 Fibonacci Series (L-B)/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function fibonacci(n) {
let a = 0, b = 1, result = [];
for (let i = 0; i < n; i++) {
result.push(a);
[a, b] = [b, a + b];
}
return result;
}

// Test Cases
console.log(fibonacci(5)); // [0, 1, 1, 2, 3]
console.log(fibonacci(8)); // [0, 1, 1, 2, 3, 5, 8, 13]

27 changes: 27 additions & 0 deletions 009 Largest in Array (L-B)/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Largest Number in Array

Write a function that finds and returns the largest number from a given array of integers.

---

### Example:

Input: [3, 7, 2, 9, 5]
Output: 9

Input: [10, 200, 30, 80]
Output: 200


---

### Problem added by

[SaadQasim19](https://github.com/SaadQasim19)

---

### Solution

[Click here to see the solution](./solution.js)

8 changes: 8 additions & 0 deletions 009 Largest in Array (L-B)/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function findLargest(arr) {
return Math.max(...arr);
}

// Test Cases
console.log(findLargest([3, 7, 2, 9, 5])); // 9
console.log(findLargest([10, 200, 30, 80])); // 200