From c927fc357b6b3887f659b9550fb88615139b59fc Mon Sep 17 00:00:00 2001 From: Saad Qasim Date: Sat, 12 Jul 2025 12:15:13 +0500 Subject: [PATCH] Add 3 beginner JS problems: Palindrome, Fibonacci, Largest --- 007 Palindrome Checker (L-B)/README.md | 27 +++++++++++++++++++++++ 007 Palindrome Checker (L-B)/solution.js | 15 +++++++++++++ 008 Fibonacci Series (L-B)/README.md | 28 ++++++++++++++++++++++++ 008 Fibonacci Series (L-B)/solution.js | 13 +++++++++++ 009 Largest in Array (L-B)/README.md | 27 +++++++++++++++++++++++ 009 Largest in Array (L-B)/solution.js | 8 +++++++ 6 files changed, 118 insertions(+) create mode 100644 007 Palindrome Checker (L-B)/README.md create mode 100644 007 Palindrome Checker (L-B)/solution.js create mode 100644 008 Fibonacci Series (L-B)/README.md create mode 100644 008 Fibonacci Series (L-B)/solution.js create mode 100644 009 Largest in Array (L-B)/README.md create mode 100644 009 Largest in Array (L-B)/solution.js diff --git a/007 Palindrome Checker (L-B)/README.md b/007 Palindrome Checker (L-B)/README.md new file mode 100644 index 0000000..3124235 --- /dev/null +++ b/007 Palindrome Checker (L-B)/README.md @@ -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) diff --git a/007 Palindrome Checker (L-B)/solution.js b/007 Palindrome Checker (L-B)/solution.js new file mode 100644 index 0000000..3191dc4 --- /dev/null +++ b/007 Palindrome Checker (L-B)/solution.js @@ -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 + \ No newline at end of file diff --git a/008 Fibonacci Series (L-B)/README.md b/008 Fibonacci Series (L-B)/README.md new file mode 100644 index 0000000..cf7f901 --- /dev/null +++ b/008 Fibonacci Series (L-B)/README.md @@ -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) diff --git a/008 Fibonacci Series (L-B)/solution.js b/008 Fibonacci Series (L-B)/solution.js new file mode 100644 index 0000000..06efc8f --- /dev/null +++ b/008 Fibonacci Series (L-B)/solution.js @@ -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] + \ No newline at end of file diff --git a/009 Largest in Array (L-B)/README.md b/009 Largest in Array (L-B)/README.md new file mode 100644 index 0000000..1c6b743 --- /dev/null +++ b/009 Largest in Array (L-B)/README.md @@ -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) + \ No newline at end of file diff --git a/009 Largest in Array (L-B)/solution.js b/009 Largest in Array (L-B)/solution.js new file mode 100644 index 0000000..c8fab99 --- /dev/null +++ b/009 Largest in Array (L-B)/solution.js @@ -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 + \ No newline at end of file