Repository: Upendhar10/LogicBuilding101
Branch: main
Commit: 66ffb53a6e6d
Files: 71
Total size: 73.5 KB
Directory structure:
gitextract_uj61cvru/
├── .gitignore
├── DAY01/
│ ├── Questions.md
│ └── Solutions.js
├── DAY02/
│ ├── Questions.md
│ └── Solutions.js
├── DAY03/
│ ├── Questions.md
│ └── Solutions.js
├── DAY04/
│ ├── Questions.md
│ └── Solutions.js
├── DAY05/
│ ├── Questions.md
│ └── Solutions.js
├── DAY06/
│ ├── Questions.md
│ └── Solutions.js
├── DAY07/
│ ├── Questions.md
│ └── Solutions.js
├── DAY08/
│ ├── Questions.md
│ └── Solutions.js
├── DAY09/
│ ├── Questions.md
│ └── Solutions.js
├── DAY10/
│ ├── Questions.md
│ └── Solutions.js
├── DAY11/
│ ├── Questions.md
│ └── Solutions.js
├── DAY12/
│ ├── Questions.md
│ └── Solutions.js
├── DAY13/
│ ├── Questions.md
│ └── Solutions.js
├── DAY14/
│ ├── Questions.md
│ └── Solutions.js
├── DAY15/
│ ├── Questions.md
│ └── Solutions.js
├── DAY16/
│ ├── Questions.md
│ └── Solutions.js
├── DAY17/
│ ├── Questions.md
│ ├── Solutions.js
│ └── notes.md
├── DAY18/
│ ├── Questions.md
│ └── Solutions.js
├── DAY19/
│ ├── Questions.md
│ └── Solutions.js
├── DAY20/
│ ├── Questions.md
│ └── Solutions.js
├── DAY21/
│ ├── Questions.md
│ └── Solutions.js
├── DAY22/
│ ├── Questions.md
│ └── Solutions.js
├── DAY23/
│ ├── Questions.md
│ └── Solutions.js
├── DAY24/
│ ├── Questions.md
│ └── Solutions.js
├── DAY25/
│ ├── Questions.md
│ └── Solutions.js
├── DAY26/
│ ├── Questions.md
│ └── Solutions.js
├── DAY27/
│ ├── Questions.md
│ └── Solutions.js
├── DAY28/
│ ├── Questions.md
│ └── Solutions.js
├── DAY29/
│ ├── Questions.md
│ └── Solutions.js
├── DAY30/
│ ├── Questions.md
│ └── Solutions.js
├── DAY31/
│ ├── Questions.md
│ └── Solutions.js
├── DAY32/
│ ├── Questions.md
│ └── Solutions.js
├── DAY33/
│ ├── Questions.md
│ └── Solutions.js
├── DAY34/
│ ├── Questions.md
│ └── Solutions.js
└── readme.md
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.git/
================================================
FILE: DAY01/Questions.md
================================================
# DAY - 01
1. **Program to Print Integer Numbers Entered by the User:**
Write a program where the user is asked to enter an integer number, and the program prints that number back to them. For example:
- **Input:** **`42`**
- **Output:** **`You entered: 42`**
2. **Write a Program to Find the Size of `int`, `float`, `double`, and `char` on Your Computer:**
Write a program that displays the size of fundamental data types (**`int`**, **`float`**, **`double`**, and **`char`**) on your system. For example:
- **Output:**
```jsx
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
```
3. **Program to Find the Larger Number Among Two Numbers:**
Write a program to compare two integers entered by the user and print the larger one. For example:
- **Input:** **`Enter two numbers: 15, 20`**
- **Output:** **`The larger number is: 20`**
================================================
FILE: DAY01/Solutions.js
================================================
// # Program to Print Integer Numbers Entered by the User:
/*
- Since, NaN (Not-a-Number) is a special value in JavaScript, and comparing it with == or === will always return false. This is because NaN is not equal to itself by design. So we use isNaN() function
- isNaN(): This function checks if the value is NaN and returns true if it is, and false otherwise.
*/
var num = parseInt(prompt("Enter any number", 0));
isNaN(num)
? console.log(num + " is not a valid number")
: console.log("You entered: " + num);
// ----------------------------------------------------------
// # Write a Program to Find the Size of int, float, double, and char on Your Computer:
/*
- In JavaScript, we cannot directly determine the memory size of fundamental data types like int, float, or char as you would in statically typed languages like C or C++. This is because JavaScript is a dynamically typed language, and it abstracts away memory management details.
- All numbers in JavaScript, whether integers or floating points, are represented as 64-bit floating-point values (IEEE 754 standard).
- Strings are collections of characters, and their size depends on encoding (e.g., UTF-16 in JavaScript).There is no direct equivalent for a char type.
- We need to use workarounds involving buffers, typed arrays, or specialized libraries, but those are more advanced concepts for now.
*/
// ----------------------------------------------------------
// # Program to Find the Larger Number Among Two Numbers:
const num1 = parseInt(prompt("Enter num1 value", 0));
const num2 = parseInt(prompt("Enter num2 value", 0));
function findMax(num1, num2) {
if (isNaN(num1) || isNaN(num2)) {
return "Invalid Inputs";
} else {
return Math.max(num1, num2);
}
}
console.log(findMax(num1, num2));
================================================
FILE: DAY02/Questions.md
================================================
# DAY - 02
1. **Program to Check Whether the Number is Odd or Even:**
Write a program that checks whether a number entered by the user is odd or even. For example:
- **Input:** **`Enter a number: 7`**
- **Output:** **`7 is an odd number`**
2. **Program to Check Whether the Number is Divisible by 5:**
Write a program that determines if a number entered by the user is divisible by 5. For example:
- **Input:** **`Enter a number: 25`**
- **Output:** **`25 is divisible by 5.`**
3. **Program to Check Whether the Number is a Multiple of 7:**
Write a program that verifies if a number entered by the user is a multiple of 7. For example:
- **Input:** **`Enter a number: 14`**
- **Output:** **`14 is a multiple of 7.`**
---
# NOTES
## Taking Input from the user in NodeJs Environment
- Node.js provides several methods for receiving input from users, including reading from standard input (stdin), command-line arguments, and user prompts.
### Using readline-sync
- This module is used to receive input from the user synchronously, ensuring program execution line by line.
command : npm install readline-sync
#### Importing the module
const readline = require("readline-sync");
#### Enter the number
```javascript
let a = Number(readline.question());
let number = [];
for (let i = 0; i < a; ++i) {
number.push(Number(readline.question()));
}
console.log(number);
```
#### Output
2
1
2
[1,2]
================================================
FILE: DAY02/Solutions.js
================================================
let num = parseInt(prompt("Enter a number: ", 0));
//* Program to Check Whether the Number is Odd or Even:
function CheckEvenOdd(num) {
if (isNaN(num)) {
console.log("Invalid Input");
} else {
if (num % 2 == 0) {
console.log(`${num} is an even number`);
} else console.log(`${num} is an Odd number`);
}
}
CheckEvenOdd(num);
// ------------------------------------------------------------------------------------------------------
//* Program to Check Whether the Number is Divisible by 5:
function divisibleBy5(num) {
if (isNaN(num)) {
console.log("Invalid Input");
} else {
if (num % 5 == 0) {
console.log(`${num} is divisible`);
} else console.log(`${num} is not divisible by 5`);
}
}
divisibleBy5(num);
// --------------------------------------------------------------------------------------------------------
//* Program to Check Whether the Number is a Multiple of 7:
function multipleOf7(num) {
if (isNaN(num)) {
console.log("Invalid Input");
} else {
if (num % 7 === 0) {
console.log(`${num} is a multiple of 7`);
} else console.log(`${num} is not divisible by 7`);
}
}
================================================
FILE: DAY03/Questions.md
================================================
# DAY - 03
1. **Program to Calculate the Square and Cube of a Number:**
Write a program where the user enters a number, and the program calculates its square and cube. For example:
- **Input:** **`Enter a number: 3`**
- **Output:** **`Square: 9, Cube: 27`**
2. **Program to Calculate the Area of a Circle and Triangle:**
Write a program to calculate the area of a circle given its radius and a triangle given its base and height. For example:
- **Input:** **`Radius: 5, Base: 10, Height: 4`**
- **Output:**
```markdown
Area of Circle: 78.5
Area of Triangle: 20
```
3. **Write a Program to Find the Quotient and Remainder of Two Integers:**
Write a program where the user enters two integers (divisor and dividend) and calculates their quotient and remainder. For example:
- **Input:** **`Dividend: 22, Divisor: 7`**
- **Output:**
```markdown
Quotient: 3
Remainder: 1
```
================================================
FILE: DAY03/Solutions.js
================================================
// # Program to Calculate the Square and Cube of a Number
let num = parseInt(prompt("Enter a number", 0));
findSquareAndCube(num);
function findSquareAndCube(num) {
if (isNaN(num)) {
console.log("Invalid Input");
return;
} else {
console.log(`Square of the ${num} : ${num * num}`);
console.log(`Cube of the ${num} : ${num * num * num}`);
}
}
// -----------------------------------------------------------------------------------------------------------------------
// # Program to Calculate the Area of a Circle and Triangle
let radius = parseInt(prompt("Enter the radius of the circle", 1));
let base = parseInt(prompt("Enter the base of the triangle", 1));
let height = parseInt(prompt("Enter the heght of the triangle", 1));
AreaOfCircleAndTriangle(radius, base, height);
function AreaOfCircleAndTriangle(radius, base, height) {
if (isNaN(radius) || isNaN(base) || isNaN(height)) {
console.log("Invalid Input");
return;
}
circleArea(radius);
triangleArea(base, height);
}
function circleArea(radius) {
let area = Math.round(Math.PI * radius * radius);
console.log(`Area of the circle : ${area}`);
}
function triangleArea(base, height) {
let area = Math.round(0.5 * base * height);
console.log(`Area of the triangle : ${area}`);
}
// -----------------------------------------------------------------------------------------------------------------------
// # Write a Program to Find the Quotient and Remainder of Two Integers
let divisor = parseInt(prompt("Enter the divisor", 1));
let dividend = parseInt(prompt("Enter the dividend", 1));
findQuotientAndRemainder(divisor, dividend);
function findQuotientAndRemainder(divisor, dividend) {
if (isNaN(divisor) || isNaN(dividend)) {
console.log("Invalid Input");
return;
}
if (divisor === 0) {
console.log("ERROR : Divide by Zero");
return;
}
let Quotient = Math.floor(dividend / divisor);
let remainder = dividend % divisor;
console.log(`Quotient : ${Quotient} and Remainder : ${remainder} `);
}
================================================
FILE: DAY04/Questions.md
================================================
# DAY - 04
1. **Print the Multiplication Table of a Given Number:**
Write a program where the user enters a number, and the program prints its multiplication table. For example:
- **Input:** **`Enter a number: 5`**
- **Output:**
```jsx
5 x 1 = 5
5 x 2 = 10
...
5 x 10 = 50
```
2. **Write a Program to Make a Simple Calculator Using a Switch Case:**
Write a program that acts as a calculator, taking two numbers and an operator (**`+`**, **`-`**, **`*`**, **`/`**) from the user, and performing the operation based on the operator. For example:
- **Input:** **`Enter first number: 10, Operator: +, Second number: 20`**
- **Output:** **`10 + 20 = 30`**
3. **Print a Number in Reverse Order:**
Write a program where the user enters a number, and the program prints it in reverse order. For example:
- **Input:** **`1234`**
- **Output:** **`4321`**
================================================
FILE: DAY04/Solutions.js
================================================
//* Print the Multiplication Table of a Given Number
let number = 5;
function PrintTable(num) {
for (let i = 1; i <= 10; i++) {
console.log(`${num} x ${i} = ${num * i} `);
}
}
PrintTable(number);
// --------------------------------------------------------------------------------------------------------------------
//* Write a Program to Make a Simple Calculator Using a Switch Case
let Operand1 = 12;
let Operand2 = 13;
let Operator = "*";
function Calculator() {
switch (Operator) {
case "+":
console.log(`Addition: ${Operand1 + Operand2}`);
break;
case "-":
console.log(`Subtraction: ${Operand1 - Operand2}`);
break;
case "*":
console.log(`Multiplication: ${Operand1 * Operand2}`);
break;
case "/":
console.log(`Division: ${(Operand1 / Operand2).toFixed(2)}`);
break;
default:
console.log("Invalid Operator");
break;
}
}
Calculator(Operand1, Operand2, Operator);
// ----------------------------------------------------------------------------------------------------------------
//* Print a Number in Reverse Order
let num = 1234;
function PrintReverseNum(num) {
let reverse = null;
while (num > 0) {
let rem = num % 10;
reverse = reverse * 10 + rem;
num = Math.floor(num / 10);
}
return reverse;
}
console.log(PrintReverseNum(num));
================================================
FILE: DAY05/Questions.md
================================================
# DAY - 05
1. **Calculate the Sum of Digits of a Given Number:**
Write a program that calculates the sum of the digits of a number entered by the user. For example:
- **Input:** **`Enter a number: 1234`**
- **Output:** **`Sum of digits: 10`**
2. **Write a Program to Check Whether a Character is a Vowel or Consonant:**
Write a program to check whether a character entered by the user is a vowel (**`a, e, i, o, u`**) or a consonant. For example:
- **Input:** **`Enter a character: e`**
- **Output:** **`e is a vowel.`**
3. **Write a Program to Find the ASCII Value of a Character:**
Write a program that takes a character as input and displays its ASCII value. For example:
- **Input:** **`Enter a character: A`**
- **Output:** **`ASCII value of A: 65`**
================================================
FILE: DAY05/Solutions.js
================================================
//* Calculate the Sum of Digits of a Given Number
let number = 1234;
function findSumOfDigits(num) {
let sum = 0;
while (num > 0) {
let rem = num % 10;
sum += rem;
num = Math.floor(num / 10);
}
return sum;
}
console.log(`The Sum of Digits of ${number} :`, findSumOfDigits(number));
// -----------------------------------------------------------------------------------------------------------
//* Write a Program to Check Whether a Character is a Vowel or Consonant
let char = "Z";
function checkCharacter(char) {
if (char.length != 1 || !/[a-zA-Z]/.test(char)) {
return "Invalid Input";
}
let letter = char.toLowerCase();
if ("aeiou".includes(letter)) {
return `${char} is an Vowel`;
} else {
return `${char} is a Consonant`;
}
}
console.log(checkCharacter(char));
// ------------------------------------------------------------------------------------------------------------
//* Write a Program to Find the ASCII Value of a Character
let Value = "@";
function findASCIIValue(val) {
if (val === " " || val.length != 1) {
return "Invalid Input";
}
return `ASCII value of ${val}: ${val.charCodeAt(0)}`;
}
console.log(findASCIIValue(Value));
================================================
FILE: DAY06/Questions.md
================================================
# DAY - 06
## Pattern 1: Sqaure
```
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
```
## Pattern 2: Right-angled trinagle
```
*
* *
* * *
* * * *
* * * * *
```
## Pattern 3: Hallow Rectangle
```
* * * * *
* *
* *
* *
* * * * *
```
================================================
FILE: DAY06/Solutions.js
================================================
//* Pattern - 1
function Pattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = "";
for (let j = 1; j <= n; j++) {
rowPattern += "* ";
}
console.log(rowPattern);
}
}
console.log("Pattern - 1");
Pattern1(5);
// --------------------------------------------------------------------------------------
//* Pattern - 2
function pattern2(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
console.log(rowPattern);
}
}
console.log("Pattern - 2");
pattern2(5);
// --------------------------------------------------------------------------------------
//* Pattern - 3
function Pattern3(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 1; j <= n; j++) {
if (i == 1 || i == n || j == 1 || j == n) {
rowPattern += "* ";
} else {
rowPattern += " ";
}
}
console.log(rowPattern.trim());
}
}
console.log("Pattern - 3");
Pattern3(5);
================================================
FILE: DAY07/Questions.md
================================================
# DAY - 07
## Pattern 1: Inverted Right-angled triangle
```
* * * * *
* * * *
* * *
* *
*
```
## Pattern 2: traingle
```
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
```
## Pattern 3: Inverted traingle
```
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
```
================================================
FILE: DAY07/Solutions.js
================================================
//* Pattern-1 :
function Pattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = n; j >= i; j--) {
rowPattern += "* ";
}
console.log(rowPattern.trim());
}
}
Pattern1(5);
// ---------------------------------------------------------------------------------------------------------------------------------------
// * Pattern - 2 :
function Pattern2(n) {
for (let i = 1; i <= n; i++) {
// rows
let rowPattern = " ";
for (let j = 1; j <= n - i; j++) {
// spaces
rowPattern += ". ";
}
for (let k = 1; k <= 2 * i - 1; k++) {
// starts
rowPattern += "* ";
}
console.log(rowPattern.trim());
}
}
Pattern2(5);
// ---------------------------------------------------------------------------------------------------------------------------
//* Pattern - 3
function Pattern3(n) {
for (let i = n; i >= 1; i--) {
// rows
let rowPattern = " ";
for (let j = 1; j <= n - i; j++) {
// spaces
rowPattern += ". ";
}
for (let k = 1; k <= 2 * i - 1; k++) {
// starts
rowPattern += "* ";
}
console.log(rowPattern.trim());
}
}
Pattern3(10);
================================================
FILE: DAY08/Questions.md
================================================
# DAY - 08
## Pattern 7:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
## Pattern 8
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
## Pattern 9
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
================================================
FILE: DAY08/Solutions.js
================================================
//* Pattern - 1
function Pattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += `${j} `;
}
console.log(rowPattern);
}
}
Pattern1(5);
// -------------------------------------------------------------------------
//* Pattern - 2
function Pattern2(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += `${i} `;
}
console.log(rowPattern);
}
}
Pattern2(5);
// -------------------------------------------------------------------------
//* Pattern - 3
function Pattern3(n) {
for (let i = n; i >= 1; i--) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += `${j} `;
}
console.log(rowPattern);
}
}
Pattern3(5);
================================================
FILE: DAY09/Questions.md
================================================
## Pattern 1
```
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
```
## Pattern 2
```
A
A B
A B C
A B C D
A B C D E
```
## Pattern 3
```
A B C D E
A B C D
A B C
A B
A
```
================================================
FILE: DAY09/Solutions.js
================================================
//* Pattern - 1
function Pattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += `${j} `;
}
for (let k = 1; k <= 2 * (n - i); k++) {
rowPattern += " ";
}
for (let l = i; l >= 1; l--) {
rowPattern += `${l} `;
}
console.log(rowPattern);
}
}
Pattern1(5);
// --------------------------------------------------------------------------------------
//* Pattern - 2
function Pattern2(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 0; j < i; j++) {
rowPattern += String.fromCharCode(65 + j) + " ";
}
console.log(rowPattern.trim());
}
}
Pattern2(5);
// --------------------------------------------------------------------------------------
//* Pattern - 3
function Pattern3(n) {
for (let i = n; i >= 1; i--) {
let rowPattern = " ";
for (let j = 0; j < i; j++) {
rowPattern += String.fromCharCode(65 + j) + " ";
}
console.log(rowPattern.trim());
}
}
Pattern3(5);
================================================
FILE: DAY10/Questions.md
================================================
## Pattern 1
```
A
B B
C C C
D D D D
E E E E E
```
## Pattern 2
```
A
A B A
A B C B A
A B C D C B A
```
## **Program to Perform Swapping of Two Numbers:**
Write a program to swap two numbers entered by the user. For example:
- **Input:** **`Enter first number: 10, Enter second number: 20`**
- **Output:**
```
Before swapping: a = 10, b = 20
After swapping: a = 20, b = 10
```
================================================
FILE: DAY10/Solutions.js
================================================
//* Pattern - 1
function Pattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += String.fromCharCode(65 + i - 1) + " ";
}
console.log(rowPattern.trim());
}
}
Pattern1(5);
// ---------------------------------------------------------------------------------------------------
//* Pattern - 2
function Pattern2(n) {
for (let i = 0; i < n; i++) {
let rowPattern = " ";
for (let j = 0; j < n - i; j++) {
rowPattern += `. `;
}
for (let k = 0; k < i; k++) {
rowPattern += String.fromCharCode(65 + k) + " ";
}
for (let l = 0; l <= i; l++) {
rowPattern += String.fromCharCode(65 + i - l) + " ";
}
console.log(rowPattern.trim());
}
}
Pattern2(4);
// ---------------------------------------------------------------------------------------------------
//* Question - 3
let number1 = 10;
let number2 = 28;
console.log("Before Swap");
console.log(`Number1 : ${number1}`);
console.log(`Number2 : ${number2}`);
function SwapTwoNumbers1(num1, num2) {
let temp = null;
temp = num1;
num1 = num2;
num2 = temp;
console.log("After Swap");
console.log(`Number1 : ${num1}`);
console.log(`Number2 : ${num2}`);
}
SwapTwoNumbers1(number1, number2);
function SwapTwoNumbers2(num1, num2) {
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
console.log("After Swap");
console.log(`Number1 : ${num1}`);
console.log(`Number2 : ${num2}`);
}
// SwapTwoNumbers2(number1, number2);
================================================
FILE: DAY11/Questions.md
================================================
# DAY - 11
1. **Write a Program to Find the Largest Number Among Three Numbers:**
Write a program where the user enters three numbers, and the program finds and displays the largest number among them. For example:
- **Input:** **`Enter three numbers: 12, 25, 7`**
- **Output:** **`The largest number is: 25`**
2. **Write a Program to Check Whether a Year Entered by the User is a Leap Year:**
Write a program to determine whether a given year is a leap year. For example:
- **Input:** **`Enter a year: 2024`**
- **Output:** **`2024 is a leap year.`**
3. **Write a Program to Calculate the Sum of the First N Natural Numbers:**
Write a program where the user enters a number **`N`**, and the program calculates the sum of all natural numbers up to **`N`**. For example:
- **Input:** **`Enter a number: 5`**
- **Output:** **`The sum of the first 5 natural numbers is 15.`**
================================================
FILE: DAY11/Solutions.js
================================================
//* Program to Find the Largest Number Among Three Numbers
function LargestAmongThreeNums(num1, num2, num3) {
if (num1 > num2) {
if (num1 > num3) {
console.log(`${num1} is Largest`);
} else {
console.log(`${num3} is Largest`);
}
} else {
if (num2 > num3) {
console.log(`${num2} is Largest`);
} else {
console.log(`${num3} is Largest`);
}
}
}
LargestAmongThreeNums(-3, -2, -1);
// --------------------------------------------------------------
//* Program to Check Whether a Year Entered by the User is a Leap Year
function isLeapYear(year) {
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
console.log(`${year} is a Leap year`);
} else {
console.log(`${year} is not a Leap Year`);
}
}
isLeapYear(2024);
// --------------------------------------------------------------
//* Program to Calculate the Sum of the First N Natural Numbers
function SumOfFirstNnaturalNums(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return `Sum : ${sum}`;
}
console.log(SumOfFirstNnaturalNums(5));
================================================
FILE: DAY12/Questions.md
================================================
# DAY - 12
1. **Factorial of a Number Using a For Loop:**
Write a program to calculate the factorial of a number entered by the user using a **`for`** loop. For example:
- **Input:** **`Enter a number: 4`**
- **Output:** **`Factorial of 4 is 24.`**
2. **Print Fibonacci Series:**
Write a program to print the Fibonacci series up to a number **`N`** entered by the user. For example:
- **Input:** **`Enter the number of terms: 7`**
- **Output:** **`Fibonacci series: 0 1 1 2 3 5 8`**
3. **Write a Program to Find the GCD or HCF of Two Numbers:**
Write a program where the user enters two numbers, and the program calculates their greatest common divisor (GCD) or highest common factor (HCF). For example:
- **Input:** **`Enter two numbers: 60, 48`**
- **Output:** **`The GCD of 60 and 48 is 12.`**
================================================
FILE: DAY12/Solutions.js
================================================
//* Factorial of a Number Using a For Loop
function FindFactorial(n) {
let fact = 1;
for (let i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
console.log(FindFactorial(4));
// ---------------------------------------------------------------------------------
//* Print Fibonacci Series
function PrintFibonacciSeries(n) {
let prev = 0,
next = 1;
let series = `${prev} ${next}`;
for (let i = 2; i < n; i++) {
let result = prev + next;
series += ` ${result}`;
prev = next;
next = result;
}
console.log(series);
}
PrintFibonacciSeries(7);
// ---------------------------------------------------------------------------------
//* Write a Program to Find the GCD or HCF of Two Numbers
function findHCF(num1, num2) {
let hcf = 1;
// let i = Math.min(num1, num2); i >= 1; i--
for (let i = 1; i < Math.min(num1, num2); i++) {
if (num1 % i === 0 && num2 % i === 0) {
hcf = i;
}
}
return hcf;
}
console.log(findHCF(60, 48));
================================================
FILE: DAY13/Questions.md
================================================
# DAY - 13
1. **Write a Program to Find the LCM of Two Numbers:**
Write a program where the user enters two numbers, and the program calculates their least common multiple (LCM). For example:
- **Input:** **`Enter two numbers: 4, 6`**
- **Output:** **`The LCM of 4 and 6 is 12.`**
2. **Write a Program to Calculate the Power of a Number:**
Write a program that takes a base and an exponent as input and calculates the power of the base raised to the exponent using both manual calculation and the **`pow()`** function. For example:
- **Input:** **`Base: 2, Exponent: 3`**
- **Output:**
```markdown
Result using manual calculation: 8
Result using pow(): 8
```
3. **Program to Print Integers in Words:**
Write a program that converts each digit of an integer entered by the user into its corresponding word representation. For example:
- **Input:** **`Enter a number: 123`**
- **Output:** **`One Two Three`**
================================================
FILE: DAY13/Solutions.js
================================================
//* Write a Program to Find the LCM of Two Numbers
function findLCM(num1, num2) {
if (num1 === 0 || num2 === 0) {
return "LCM is not defined for zero.";
}
let lcm = null;
let max = Math.max(Math.abs(num1), Math.abs(num2));
while (true) {
if (max % num1 == 0 && max % num2 == 0) {
lcm = max;
break;
}
max++;
}
return lcm;
}
console.log(findLCM(5, 7));
// -----------------------------------------------------------------------------------------------------------
//* Write a Program to Calculate the Power of a Number
function findPowerManual(base, expo) {
let power = base ** expo;
return power;
}
// console.log(findPowerManual(2, 3));
function findPowerBuiltIn(base, expo) {
let power = Math.pow(base, expo);
return power;
}
console.log(findPowerBuiltIn(2, 3));
// -----------------------------------------------------------------------------------------------------------
//* Program to Print Integers in Words
function DigitToWord(num) {
const digitToWord = [
"Zero",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
];
let numStr = num.toString();
let result = " ";
for (let i = 0; i < numStr.length; i++) {
let char = numStr[i];
if (char === "-") {
result += "Negative ";
} else {
result += digitToWord[parseInt(char)] + " ";
}
}
return result.trim();
}
console.log(DigitToWord(1028));
================================================
FILE: DAY14/Questions.md
================================================
# DAY - 14
1. **Print Numbers in Words in Reverse Order Using a Switch Case:**
Write a program that takes an integer, reverses it, and prints each digit as a word using a **`switch`** case. For example:
- **Input:** **`Enter a number: 321`**
- **Output:** **`One Two Three`**
2. **Write a Program to Display All Factors of a Number:**
Write a program to find and print all factors of a number entered by the user. For example:
- **Input:** **`Enter a number: 28`**
- **Output:** **`Factors of 28: 1, 2, 4, 7, 14, 28`**
3. **Amstrong Number or Not:**
Write a program to check if a number is an Armstrong number. For example:
- **Input:** **`Enter a number: 153`**
- **Output:** **`153 is an Armstrong number.`**
================================================
FILE: DAY14/Solutions.js
================================================
//* Print Numbers in Words in Reverse Order Using a Switch Case
function NumToWordsReverse(num) {
if (isNaN(num)) {
console.log("Invalid Input");
return;
}
let result = "";
if (num < 0) {
result += "Negative ";
num = Math.abs(num);
}
while (num > 0) {
let digit = num % 10;
switch (digit.toString()) {
case "0":
result += "Zero ";
break;
case "1":
result += "One ";
break;
case "2":
result += "Two ";
break;
case "3":
result += "Three ";
break;
case "4":
result += "Four ";
break;
case "5":
result += "Five ";
break;
case "6":
result += "Six ";
break;
case "7":
result += "Seven ";
break;
case "8":
result += "Eight ";
break;
case "9":
result += "Nine ";
break;
}
num = Math.floor(num / 10);
}
return result;
}
console.log(NumToWordsReverse(-321));
// -----------------------------------------------------------
//* Write a Program to Display All Factors of a Number
function PrintFactors(n) {
let result = [];
for (let i = 1; i <= n; i++) {
if (n % i === 0) {
result.push(i);
}
}
return result;
}
console.log(PrintFactors(28));
// ----------------------------------------------------------
//* Amstrong Number or Not:
function ValidAmstrong(num) {
if (isNaN(num) || num < 0) {
console.log("Invalid Input, Please enter a non-negative integer.");
return;
}
let OriginalNum = num;
let DigitCount = num.toString().length;
let result = 0;
while (num > 0) {
let digit = num % 10;
result += digit ** DigitCount;
num = Math.floor(num / 10);
}
result === OriginalNum
? console.log(`${OriginalNum} is an Amstrong Number`)
: console.log(`${OriginalNum} is not an Amstrong Number`);
}
ValidAmstrong(1634);
================================================
FILE: DAY15/Questions.md
================================================
# DAY - 15
1. **Check Whether a Number is Prime or Not:**
Write a program that checks if a number entered by the user is a prime number. For example:
- **Input:** **`Enter a number: 17`**
- **Output:** **`17 is a prime number.`**
2. **Print Prime Numbers Within a Range:**
Write a program to display all prime numbers between two intervals entered by the user. For example:
- **Input:** **`Enter two numbers: 10, 30`**
- **Output:** **`Prime numbers between 10 and 30: 11, 13, 17, 19, 23, 29`**
3. **Print Factorial Series:**
Write a program that prints the factorial of numbers from 1 to **`N`**, where the user enters N. For example:
- **Input:** **`Enter a number: 5`**
- **Output:**
```
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
```
================================================
FILE: DAY15/Solutions.js
================================================
//* Check Whether a Number is Prime or Not
function ValidPrime(num) {
if (num <= 1) {
return `${num} is Not Prime`;
}
if (num == 2) {
return `${num} is Prime`;
}
if (num % 2 === 0) {
return `${num} is Not Prime`;
}
for (let i = 3; i <= Math.sqrt(num); i += 2) {
if (num % i === 0) {
return `${num} is Not Prime`;
}
}
return `${num} is Prime`;
}
console.log(ValidPrime(5));
// -----------------------------------------------------------
//* Print Prime Numbers Within a Range
function PrimeNumsInRange(start, end) {
let result = [];
for (let i = Math.max(start, 2); i <= end; i++) {
let isPrime = true;
for (let j = 2; j <= Math.sqrt(i); j++) {
if (i % j === 0) {
isPrime = false;
break;
}
}
if (isPrime) result.push(i);
}
return result;
}
console.log(PrimeNumsInRange(5, 15));
// -----------------------------------------------------------
//* Print Factorial Series
function PrintFactorialSeries1(num) {
for (let i = 1; i <= num; i++) {
let fact = 1;
for (let j = 1; j <= i; j++) {
fact = fact * j;
}
console.log(`${i}! = ${fact}`);
}
}
// PrintFactorialSeries1(5);
function PrintFactorialSeries2(num) {
let fact = 1;
for (let i = 1; i <= num; i++) {
fact = fact * i;
console.log(`${i}! = ${fact}`);
}
}
PrintFactorialSeries2(5);
================================================
FILE: DAY16/Questions.md
================================================
# DAY - 16
1. **Write a Program to Check Whether a Number is a Palindrome:**
Write a program to determine if a number is a palindrome. For example:
- **Input:** **`Enter a number: 121`**
- **Output:** **`121 is a palindrome.`**
2. **Check if an Integer Can Be Expressed as the Sum of Two Prime Numbers:**
Write a program to check if a number can be expressed as the sum of two prime numbers. Print all such combinations. For example:
- **Input:** **`Enter a number: 34`**
- **Output:**
```
34 = 3 + 31
34 = 5 + 29
34 = 11 + 23
34 = 17 + 17
```
3. **Print All Digits and Alphabets Using a For Loop:**
Write a program to print all digits (0–9) and alphabets (A–Z, a–z) using a **`for`** loop. For example:
- **Output:**
```markdown
Digits: 0 1 2 3 4 5 6 7 8 9
Alphabets: A B C ... Z a b c ... z
```
================================================
FILE: DAY16/Solutions.js
================================================
//* Write a Program to Check Whether a Number is a Palindrome
function ValidPalindrome(num) {
if (isNaN(num)) {
return "Invalid Input!";
}
let OriginalNum = num;
let reversedNum = 0;
while (num > 0) {
let rem = num % 10;
reversedNum = reversedNum * 10 + rem;
num = Math.floor(num / 10);
}
console.log(reversedNum);
if (OriginalNum === reversedNum) {
return `${OriginalNum} is a Valid Palindrome`;
}
return `${OriginalNum} is not a Valid Palindrome`;
}
console.log(ValidPalindrome(12));
// ----------------------------------------------------------------------
//* Check if an Integer Can Be Expressed as the Sum of Two Prime Numbers
function isPrime(n) {
if (n < 1) return false;
for (let i = 2; i < Math.sqrt(n); i++) {
if (n % i === 0) return false;
}
return true;
}
function SumOfTwoPrimes(N) {
let Primes = [];
for (let i = 2; i <= N / 2; i++) {
let compliment = N - i;
if (isPrime(i) && isPrime(compliment)) {
Primes.push(`${N} = ${i} + ${compliment}`);
// Primes.push(i, compliment);
}
}
if (Primes.length === 0) {
console.log(`${N} cannot be expressed as the sum of two prime numbers`);
} else {
console.log(Primes.join("\n"));
}
}
SumOfTwoPrimes(34);
// -------------------------------------------------------------------------
//* Print All Digits and Alphabets Using a For Loop
function PrintNumbers() {
let Digits = [];
for (let i = 0; i < 10; i++) {
Digits.push(i);
}
return Digits;
}
function PrintAlphabets() {
let Alphabets = [];
for (let i = "A".charCodeAt(0); i <= "Z".charCodeAt(0); i++) {
Alphabets.push(String.fromCharCode(i));
}
for (let i = "a".charCodeAt(0); i <= "z".charCodeAt(0); i++) {
Alphabets.push(String.fromCharCode(i));
}
return Alphabets;
}
console.log(PrintNumbers());
console.log(PrintAlphabets());
================================================
FILE: DAY17/Questions.md
================================================
# DAY - 17
1. **Write a Program to Convert Binary Numbers to Decimal and Vice Versa Manually:**
Write a program that uses user-defined functions to convert binary numbers to decimal and decimal numbers to binary. For example:
- **Input:** **`Enter a binary number: 1010`**
- **Output:** **`Decimal equivalent: 10`**
- **Input:** **`Enter a decimal number: 10`**
- **Output:** **`Binary equivalent: 1010`**
2. Pattern - 1
```
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
```
3. Pattern - 2
```
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
```
================================================
FILE: DAY17/Solutions.js
================================================
//* Program to Convert Binary Numbers to Decimal and Vice Versa Manually:
// Function to convert Binary to Decimal
function binaryToDecimal(binary) {
let decimal = 0;
let position = 0;
while (binary > 0) {
let digit = binary % 10; // Extract the last digit
decimal += digit * Math.pow(2, position); // Multiply by 2^position
position++;
binary = Math.floor(binary / 10); // Remove the last digit
}
return decimal;
}
// Function to convert Decimal to Binary
function decimalToBinary(decimal) {
let binary = "";
while (decimal > 0) {
let remainder = decimal % 2; // Get remainder
binary = remainder + binary; // Add remainder to the left
decimal = Math.floor(decimal / 2); // Divide by 2
}
return binary || "0"; // If input is 0, return "0"
}
// User Input and Output
const binaryInput = 1010;
console.log(
`Binary ${binaryInput} -> Decimal: ${binaryToDecimal(binaryInput)}`
);
const decimalInput = 10;
console.log(
`Decimal ${decimalInput} -> Binary: ${decimalToBinary(decimalInput)}`
);
// -----------------------------------------------------------
//* Pattern - 1
function PrintPattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = "";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
console.log(rowPattern.trim());
}
for (let i = n - 1; i >= 1; i--) {
let rowPattern = " ";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
console.log(rowPattern.trim());
}
}
PrintPattern1(5);
// ----------------------------------------------------------
//* Pattern - 2
function PrintPattern2(n) {
// Upper half of the pattern
for (let i = 1; i <= n; i++) {
let rowPattern = " ".repeat(n - i) + "* ".repeat(i * 2 - 1);
console.log(rowPattern);
// console.log(rowPattern.trim());
}
// Lower half of the pattern
for (let i = n - 1; i >= 1; i--) {
let rowPattern = " ".repeat((n - i) * 2) + "* ".repeat(i * 2 - 1);
console.log(rowPattern);
}
}
PrintPattern2(5);
================================================
FILE: DAY17/notes.md
================================================
## Binary to Decimal Conversion:
### Binary Number:
- A binary number is made up of 0's and 1's and uses base 2.
- To convert a binary number to decimal, multiply each binary digit (bit) by 2nd position, where the position starts from 0 (right to left).
Add up all these values to get the decimal number
---
## Decimal to Binary Conversion:
### Decimal Number:
- A number using base 10 (0-9 digits).
- To convert to binary: Repeatedly divide the decimal number by 2.
- Record the remainder at each step (this will be the binary digit).
- Continue until the quotient becomes 0.
- Read the remainders from bottom to top to get the binary number.
---
## repeat() method
- The repeat() method in JavaScript is a built-in method for strings.
- It allows a string to be repeated a specified number of times.
### Syntax:
string.repeat(count); where
- string: The string to repeat.
- count: The number of times to repeat the string. This must be a non-negative integer.
================================================
FILE: DAY18/Questions.md
================================================
# DAY - 18
**Pattern - 1**
```
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
```
**Pattern - 2**
```
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
```
**Pattern - 3**
```
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
```
================================================
FILE: DAY18/Solutions.js
================================================
//* Pattern - 1
function PrintPattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = "";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
for (let k = 1; k <= 2 * (n - i); k++) {
rowPattern += " ";
}
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
console.log(rowPattern);
}
for (let i = n - 1; i >= 1; i--) {
let rowPattern = "";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
for (let k = 1; k <= 2 * (n - i); k++) {
rowPattern += " ";
}
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
console.log(rowPattern);
}
}
PrintPattern1(5);
function PrintPattern1Optimized(n) {
for (let i = 1; i <= 2 * n - 1; i++) {
// Determine the row index
let rowIndex = i <= n ? i : 2 * n - i;
// Left stars
let leftStars = "* ".repeat(rowIndex);
// Middle spaces
let middleSpaces = " ".repeat(2 * (n - rowIndex));
// Right stars
let rightStars = "* ".repeat(rowIndex);
// Print the complete row
console.log(leftStars + middleSpaces + rightStars);
}
}
// PrintPattern1Optimized(5);
// -----------------------------------------------------------
//* Pattern - 2
function PrintPattern2(n) {
for (let i = n; i >= 1; i--) {
rowPattern = "";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
for (let k = 1; k <= 2 * (n - i); k++) {
rowPattern += " ";
}
for (let l = 1; l <= i; l++) {
rowPattern += "* ";
}
console.log(rowPattern);
}
for (let i = 1; i <= n; i++) {
rowPattern = "";
for (let j = 1; j <= i; j++) {
rowPattern += "* ";
}
for (let k = 1; k <= 2 * (n - i); k++) {
rowPattern += " ";
}
for (let l = 1; l <= i; l++) {
rowPattern += "* ";
}
console.log(rowPattern);
}
}
PrintPattern2(5);
// ----------------------------------------------------------
//* Pattern - 3
function PrintPattern3(n) {
let num = 1;
for (let i = 1; i <= n; i++) {
let rowPattern = "";
for (let j = 1; j <= i; j++) {
rowPattern += num + " ";
num++;
}
console.log(rowPattern);
}
}
PrintPattern3(5);
================================================
FILE: DAY19/Questions.md
================================================
# DAY - 19
## Pattern 1:
```
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
```
## Pattern 2:
```
4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 4 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
```
## Pattern 3:
```
E
D E
C D E
B C D E
A B C D E
```
================================================
FILE: DAY19/Solutions.js
================================================
//* Pattern - 1
function PrintPattern1(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = "";
for (let j = 1; j <= i; j++) {
if ((i + j) % 2 == 0) {
rowPattern += 1 + " ";
} else {
rowPattern += 0 + " ";
}
}
console.log(rowPattern);
}
}
PrintPattern1(5);
// --------------------------------------------------------------------------------
//* Pattern - 2
function PrintPattern2(n) {
let size = 2 * n - 1;
for (let i = 1; i <= size; i++) {
let rowPattern = "";
for (let j = 1; j <= size; j++) {
let value =
n -
Math.min(
Math.min(i - 1, size - i), // Distance from top or bottom edge
Math.min(j - 1, size - j) // Distance from left or right edge
);
rowPattern += `${value} `;
}
console.log(rowPattern);
}
}
PrintPattern2(4);
// -------------------------------------------------------------------------------
//* Pattern - 3
function PrintPattern3(n) {
let startChar = "E".charCodeAt(0);
for (let i = 1; i <= n; i++) {
let rowPattern = "";
let currentChar = startChar - i;
for (let j = 1; j <= i; j++) {
rowPattern += String.fromCharCode(currentChar + j) + " ";
}
console.log(rowPattern);
}
}
PrintPattern3(5);
================================================
FILE: DAY20/Questions.md
================================================
# DAY - 20
## Pattern 1
```
*
* *
* *
* *
* *
* *
*
```
## Pattern 2
```
1
1 2 1
1 2 3 2 1
```
## Pattern 3
```
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
```
================================================
FILE: DAY20/Solutions.js
================================================
//* Pattern - 1
function PrintPattern1(n) {
// Top half of the diamond
for (let i = 1; i <= n; i++) {
let rowPattern = "";
rowPattern += " ".repeat(n - i);
// Print stars and spaces
for (let j = 1; j <= 2 * i - 1; j++) {
if (j === 1 || j === 2 * i - 1) {
rowPattern += "*";
} else {
rowPattern += " ";
}
}
console.log(rowPattern);
}
// Bottom half of the diamond
for (let i = n - 1; i >= 1; i--) {
let rowPattern = "";
rowPattern += " ".repeat(n - i);
// Print stars and spaces
for (let j = 1; j <= 2 * i - 1; j++) {
if (j === 1 || j === 2 * i - 1) {
rowPattern += "*";
} else {
rowPattern += " ";
}
}
console.log(rowPattern);
}
}
PrintPattern1(4);
// ----------------------------------------------------------
//* Pattern - 2
function PrintPattern2(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = "";
// Print leading spaces
rowPattern += ".".repeat(2 * (n - i));
// Print ascending numbers
for (let j = 1; j <= i; j++) {
rowPattern += j + " ";
}
// Print descending numbers
for (let j = i - 1; j >= 1; j--) {
rowPattern += j + " ";
}
console.log(rowPattern.trim());
}
}
PrintPattern2(3);
// ----------------------------------------------------------
//* Pattern - 3
function PrintPattern3(n) {
for (let i = 1; i <= n; i++) {
let rowPattern = "";
for (let j = 1; j <= n; j++) {
if ((i + j) % 2 == 0) {
rowPattern += "0 ";
} else {
rowPattern += "1 ";
}
}
console.log(rowPattern);
}
}
PrintPattern3(4);
================================================
FILE: DAY21/Questions.md
================================================
# DAY - 21
1. **Perfect Number**
Write a program to determine if a number is a perfect number.
- **Input:** **`number = 6`**
- **Output:** **`Perfect Number`**
- Explanation: 6 is a perfect number because its divisors (1, 2, 3) sum up to 6.
2. **Largest Prime Factor**
Write a program to find the largest prime factor of a given number.
- **Input:** **`number = 28`**
- **Output:** **`7`**
3. **Sum of the series of n terms**
Write a program to calculate the sum of the series 1 + 1/2 + 1/3 + ... + 1/n up to the nth term.
- **Input:** **`n = 4`**
- **Output:** **`2.083333`**
================================================
FILE: DAY21/Solutions.js
================================================
//* Perfect Number
function PerfectNum(n) {
if (n <= 0) {
return `Input must be Posivitve Number`;
}
let sum = 0;
for (let i = 1; i < n; i++) {
if (n % i === 0) {
sum += i;
}
}
sum === n
? console.log(`${n} is a Perfect Number`)
: console.log(`${n} is Not a perfect number`);
}
PerfectNum(28);
// ----------------------------------------------------------
//* Largest Prime Factor
function isPrime(n) {
if (n <= 1) return false;
for (let i = 2; i < Math.sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
}
function LargestPrimeFactor(num) {
if (num <= 1) return "No prime factors";
let MaxPrime = -1;
for (let i = 2; i < Math.sqrt(num); i++) {
if (num % i == 0 && isPrime(i)) {
MaxPrime = i;
}
}
// Check if the remaining number is a prime factor
// if (num > 1 && isPrime(num)) {
// MaxPrime = num;
// }
return MaxPrime;
}
console.log(LargestPrimeFactor(13195));
// ---------------------------------------------------------
//* Sum of Series of n terms
function SumSeries(n) {
if (n <= 0) {
return `Input must be Posivitve Number`;
}
let sum = 0;
for (let i = 1; i <= n; i++) {
sum = sum + 1 / i;
}
return parseFloat(sum.toFixed(3));
}
console.log(SumSeries(4));
================================================
FILE: DAY22/Questions.md
================================================
# DAY - 22
1. **Print the Array in Sorted Order (Ascending and Descending):**
Write a program to sort an array in ascending and descending order. For example:
- **Input:** **`[5, 3, 8, 1]`**
- **Output:**
```
Ascending: [1, 3, 5, 8]
Descending: [8, 5, 3, 1]
```
2. **Finding the Longest Sequence of Consecutive 1s in a Binary Array**
Write a program to find the longest sequence of consecutive 1s in a binary array.
- **Input:** binaryArray = [1, 1, 0, 1, 1, 1]
- **Output:** 3
3. **Finding the Most Frequent Element in an Array**
Write a program to find the most frequent element in an array.
- **Input:** array = [1, 2, 2, 3, 3, 3]
- **Output:** 3
================================================
FILE: DAY22/Solutions.js
================================================
//* Print the Array in Sorted Order (Ascending and Descending)
/*
Built-In Methods
Ascending Order : arr.sort((a, b) => a - b);
Descending Order : arr.sort((a, b) => b - a);
*/
function SortAscendingOrder(arr) {
for (let i = 0; i < arr.length - 1; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
function SortDescendingOrder(arr) {
for (let i = 0; i < arr.length - 1; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] < arr[j]) {
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
console.log(SortAscendingOrder([5, 3, 8, 1]));
console.log(SortDescendingOrder([5, 3, 8, 1]));
// ---------------------------------------------------------------------------
//* Finding the Longest Sequence of Consecutive 1s in a Binary Array
function LongConsequence1(arr) {
let count = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == 1) {
count++;
} else {
count = 0;
}
}
return count;
}
console.log(LongConsequence1([1, 1, 0, 1, 1, 1, 1]));
// --------------------------------------------------------------------------
//* Finding the Most Frequent Element in an Array
// Return the most frequent number, else returns -1
function MostFrequentElement(arr) {
let FrequentNum = -1;
let MaxCount = 0;
for (let i = 0; i < arr.length; i++) {
let count = 0;
for (let j = 0; j < arr.length; j++) {
if (arr[i] == arr[j]) {
count++;
}
}
if (MaxCount < count) {
MaxCount = Math.max(MaxCount, count);
MaxCount > 1 ? (FrequentNum = arr[i]) : (FrequentNum = -1);
}
}
return FrequentNum;
}
console.log(MostFrequentElement([1, 2, 3, 4, 5]));
================================================
FILE: DAY23/Questions.md
================================================
# DAY - 23
1. **Find the Missing Number in an Array**
- Given an array of numbers from 1 to n with one number missing, find the missing number.
- **Input:** **[1, 2, 4, 5, 6]**
- **Output:** **Missing Number: 3**
2. **Find the Majority Element in an Array**
- Find the element that appears more than n/2 times in the array (if any).
- **Input:** **[3, 3, 4, 2, 4, 4, 2, 4, 4]**
- **Output:** **Majority Element: 4**
3. **Reverse an Array**
- Reverse the order of elements in the given array.
- **Input:** **[1, 2, 3, 4, 5]**
- **Output:** **[5, 4, 3, 2, 1]**
================================================
FILE: DAY23/Solutions.js
================================================
//* Missing Number
function FindMissingNum(arr) {
let MissingNum = null;
let n = arr.length + 1;
let TotalSum = (n * (n + 1)) / 2;
let ActualSum = arr.reduce((acc, currNum) => acc + currNum, 0);
MissingNum = TotalSum - ActualSum;
return MissingNum;
}
console.log(FindMissingNum([1, 2, 4, 5, 6]));
// -----------------------------------------------------------------
//* Majority Element
function FindMajorityElement(arr) {
let MajorityCount = arr.length / 2;
let MajorityElem = 0;
for (let i = 0; i < arr.length; i++) {
let count = 0;
for (let j = 0; j < arr.length; j++) {
if (arr[i] == arr[j]) {
count++;
}
}
if (count > MajorityCount) {
MajorityCount = count;
MajorityElem = arr[i];
}
}
return MajorityElem;
}
console.log(FindMajorityElement([3, 3, 4, 2, 4, 4, 2, 4, 4]));
// ---------------------------------------------------------------
//* Reverse an Array
/*
arr.reverse() method returns a new array with the desired result, but it also modifies the existing array as well
arr.toReversed() method returns a new array with the desired result, but it will not modify the existing array.
*/
function ReverseArray(arr) {
// let reversedArr = arr.reverse();
let reversedArr = arr.toReversed();
// console.log(arr);
console.log(reversedArr);
}
ReverseArray([1, 2, 3, 4, 5]);
================================================
FILE: DAY24/Questions.md
================================================
# DAY - 24
1. **Find the Second Largest Element in an Array**
- Find the second largest element in the array.
- **Input:** **[10, 20, 4, 45, 99]**
- **Output:** **Second Largest: 45**
2. **Remove Duplicates from an Array**
- Remove all duplicates from the given array and return the unique elements..
- **Input:** **[1, 2, 2, 3, 4, 1, 5]**
- **Output:** **[1, 2, 3, 4, 5]**
3. **Move Zeros to the End of an Array**
- Move all zeros in the array to the end while maintaining the relative order of non-zero elements.
- **Input:** **[0, 1, 2, 0, 3, 4, 0]**
- **Output:** **[1, 2, 3, 4, 0, 0, 0]**
================================================
FILE: DAY24/Solutions.js
================================================
//* Find the Second Largest Element in an Array
function FindSecondLargest(arr) {
if (arr.length < 2) {
return "Array must have atleast two elements";
}
let FirstMax = -Infinity;
let SecondMax = -Infinity;
for (let i = 0; i < arr.length; i++) {
if (arr[i] > FirstMax) {
SecondMax = FirstMax;
FirstMax = arr[i];
} else if (arr[i] > SecondMax && arr[i] < FirstMax) {
SecondMax = arr[i];
}
}
return SecondMax;
}
console.log(FindSecondLargest([10, 20, 4, 45, 99]));
// -----------------------------------------------------------------
//* Remove Duplicates from an Array
function RemoveDuplicates(arr) {
let result = [];
for (let i = 0; i < arr.length; i++) {
let elem = arr[i];
if (!result.includes(elem)) {
result.push(elem);
}
}
return result;
}
console.log(RemoveDuplicates([1, 2, 2, 3, 4, 1, 5]));
// ----------------------------------------------------------------
//* Move Zeros to the End of an Array
function MoveZeroEnd(arr) {
let result = [];
let count = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == 0) {
count++;
}
}
for (let i = 0; i < arr.length; i++) {
if (arr[i] != 0) {
result.push(arr[i]);
}
}
for (let i = 0; i < count; i++) {
result.push(0);
}
return result;
}
console.log(MoveZeroEnd([0, 1, 2, 0, 3, 4, 0]));
================================================
FILE: DAY25/Questions.md
================================================
# DAY - 25
1. **Find the Frequency of Each Element in an Array**
Calculate the frequency of each element in the array.
- **Input: [1, 2, 2, 3, 1, 4, 5, 1]**
- **Output: {1: 3, 2: 2, 3: 1, 4: 1, 5: 1}**
2. **Check Palindrome**
Determine if a string reads the same backward as forward.
- **Input: "madam"**
- **Output: "Palindrome"**
3. **Count Words in a String**
Count the number of words in a sentence.
- **Input: "I love programming"**
- **Output: 3**
================================================
FILE: DAY25/Solutions.js
================================================
//* Find the Frequency of Each Element in an Array
function FindFrequencyofElements(arr) {
let frequency = {};
for (let num of arr) {
if (frequency[num]) {
frequency[num]++;
} else {
frequency[num] = 1;
}
}
return frequency;
}
console.log(FindFrequencyofElements([1, 2, 2, 3, 1, 4, 5, 1]));
// ---------------------------------------------------------------------
//* Check Palindrome
function checkPalindromString(str) {
let OriginalStr = str;
let reverseStr = "";
let ptrJ = str.length - 1;
for (let i = 0; i < str.length; i++) {
if (str.charAt(i) == str.charAt(ptrJ)) {
reverseStr = reverseStr + str.charAt(i);
}
ptrJ--;
}
if (reverseStr === OriginalStr) {
return `"${OriginalStr}" is a Palindrome`;
} else {
return `"${OriginalStr}" is not a Palindrome`;
}
}
console.log(checkPalindromString("madam"));
// ---------------------------------------------------------------------
//* Count Words in a String
function FindWordsCount(str) {
return str.split(" ").length;
}
console.log(FindWordsCount("I love programming"));
================================================
FILE: DAY26/Questions.md
================================================
# DAY - 27
1. **Longest Word in a Sentence**
Find the longest word in a given sentence.
- **Input: "The quick brown fox"**
- **Output: "quick"**
2. **Find the First Non-Repeating Character**
Identify the first character that does not repeat in the string.
- **Input: "swiss"**
- **Output: "w"**
3. **Find All Substrings of a String**
Print all possible substrings of a string.
- **Input: "abc"**
- **Output: ["a", "b", "c", "ab", "bc", "abc"]**
================================================
FILE: DAY26/Solutions.js
================================================
//* Longest Word in a Sentence
function LongestWord(sentence) {
let sentenceArr = sentence.split(" ");
let MaxCount = 0;
let LongWord = "";
for (let i = 0; i < sentenceArr.length; i++) {
if (sentenceArr[i].length > MaxCount) {
MaxCount = sentenceArr[i].length;
LongWord = sentenceArr[i];
}
}
return LongWord;
}
console.log(LongestWord("The quick brown fox"));
// ----------------------------------------------------------------------------
//* Find the First Non-Repeating Character
function NonRepeatingChar(str) {
let frequency = {};
let NRC = "";
for (let char of str) {
frequency[char] = (frequency[char] || 0) + 1;
}
for (let ch of str) {
if (frequency[ch] == 1) {
NRC = ch;
break;
}
}
return NRC;
}
console.log(NonRepeatingChar("swiss"));
// ----------------------------------------------------------------------------
//* Find All Substrings of a String
function PrintAllSubstrings(str) {
let result = [];
for (let i = 0; i < str.length; i++) {
for (let j = i + 1; j <= str.length; j++) {
result.push(str.substring(i, j));
}
}
return result;
}
function PrintAllSubstrings2(str) {
let result = [];
// add all single chat at once
for (let i = 0; i < str.length; i++) {
result.push(str.charAt(i));
}
// Add substrings of length and above in sequence
for (let i = 2; i <= str.length; i++) {
for (let j = 0; j <= str.length - i; j++) {
result.push(str.substring(j, j + i));
}
}
return result;
}
// console.log(PrintAllSubstrings("abc"));
console.log(PrintAllSubstrings2("abc"));
================================================
FILE: DAY27/Questions.md
================================================
# DAY 27
1. **Check Anagrams**
Determine if two strings are anagrams of each other.
- **Input: "listen", "silent"**
- **Output: "Anagrams"**
2. **Check if Two Strings are Rotations of Each Other**
Check if one string is a rotation of another.
NOTE : the order of characters matters in rotations.
- **Input: "abcd", "cdab"**
- **Output: "Yes"**
3. **Remove All Non-Alphabetic Characters**
Remove all characters that are not letters.
- **Input: "abc123!@#"**
- **Output: "abc"**
================================================
FILE: DAY27/Solutions.js
================================================
//* Check Anagrams
/*
- An anagram string refers to a pair of strings that contain the exact same characters in the same frequency, but their order can be different.
- Essentially, one string can be rearranged to form the other.
- If the two input strings are identical to each other then, they are called "Trivial Anagrams"
*/
function CheckAnagrams(str1, str2) {
if (str1.length !== str2.length) {
return "Not Anagrams";
} else if (str1 === str2) {
return "Trivial Anagrams";
}
// Sort and compare
let sortedStr1 = str1.split("").sort().join("");
let sortedStr2 = str2.split("").sort().join("");
return sortedStr1 === sortedStr2 ? "Anagrams" : "Not Anagrams";
}
console.log(CheckAnagrams("listen", "silent"));
// --------------------------------------------------------------------------
//* Check if Two Strings Have the Same Set of Characters
/*
- If str2 is a rotation of str1, then appending str1 to itself will contain str2 as a substring.
*/
function ValidRotationStrings(str1, str2) {
if (str1.length !== str2.length) {
return "NO";
} else if (str1 === str2) {
return "YES";
}
let concatenated = str1 + str1;
return concatenated.includes(str2) ? "YES" : "NO";
}
console.log(ValidRotationStrings("abcdd", "cdab"));
// --------------------------------------------------------------------------
//* Remove All Non-Alphabetic Characters
function RemoveNonAlphabets(str) {
return str.replace(/[^a-zA-Z]/g, "");
}
console.log(RemoveNonAlphabets("abc123!@#"));
================================================
FILE: DAY28/Questions.md
================================================
# DAY - 28
1. **Find Duplicate Characters in a String**
Identify all characters that appear more than once in a string.
- **Input: "programming"**
- **Output: ["r", "g", "m"]**
2. **Count Vowels and Consonants**
Count the number of vowels and consonants in a string.
- **Input: "hello"**
- **Output: Vowels: 2, Consonants: 3**
3. **Matrix Addition**
Add two matrices of the same dimensions.
- **Input:**
```
A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]
```
- **Output:**
```
[[6, 8], [10, 12]]
```
================================================
FILE: DAY28/Solutions.js
================================================
//* Find Duplicate Characters in a String
function FindDuplicatesChars(str) {
let result = [];
for (let i = 0; i < str.length; i++) {
let char = str.charAt(i);
let count = 0;
for (let j = 0; j < str.length; j++) {
if (char === str.charAt(j)) {
count++;
}
}
if (count > 1 && !result.includes(char)) {
result.push(char);
}
}
console.log(result);
}
FindDuplicatesChars("programming");
// -----------------------------------------------------------------------
//* Count Vowels and Consonants
function CountVowelsAndConsonants(str) {
let StrLen = str.length;
let Vowels = 0;
for (let i = 0; i < StrLen; i++) {
let char = str.charAt(i).toLowerCase();
if (
char === "a" ||
char === "e" ||
char === "i" ||
char === "o" ||
char === "u"
) {
Vowels++;
}
}
console.log(`Vowels:${Vowels} and Consonants: ${StrLen - Vowels}`);
}
CountVowelsAndConsonants("hello");
// ----------------------------------------------------------------------
//* Matrix Addition
/*
- To perform Addition, both matrices should have same no.of elements in row and column respectively.
- Matrix.length => No.of rows in the matrix
- Matrix[0].length => No.of columns in the first row
*/
function MatrixAddition(matrixA, matrixB) {
if (
matrixA.length !== matrixB.length ||
matrixA[0].length !== matrixB[0].length
) {
return "Two Matrices size must be same to perform Addition.";
}
let result = [];
for (let i = 0; i < matrixA.length; i++) {
let row = [];
for (let j = 0; j < matrixA[i].length; j++) {
row.push(matrixA[i][j] + matrixB[i][j]);
}
result.push(row);
}
return result;
}
// Sample Matrices
let matA = [
[1, 2],
[3, 4],
];
let matB = [
[5, 6],
[7, 8],
];
console.log(MatrixAddition(matA, matB));
================================================
FILE: DAY29/Questions.md
================================================
# DAY - 29
1. **Matrix Multiplication**
Multiply two matrices if the number of columns in the first matrix equals the number of rows in the second.
- **Input:**
```
A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]
```
- **Output:**
```
[[19, 22], [43, 50]]
```
2. **Search an Element in a Matrix**
Search for a given element in a matrix and return its position.
- **Input:**
```
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], Target = 5
```
- **Output:**
```
Position: (1, 1) (0-based index)
```
3. **Matrix Transpose**
Find the transpose of a matrix (convert rows to columns and vice versa).
- **Input:**
```
A = [[1, 2, 3], [4, 5, 6]]
```
- **Output:**
```
[[1, 4], [2, 5], [3, 6]]
```
================================================
FILE: DAY29/Solutions.js
================================================
//* Matrix Multipication
/*
# Matrix Multiplication Rules:
- The no.of rows in the matrixA should be equal to the no.of columns matrixB.
- The no.of columns in the matrixA should be equal to the no.of rows in the matrixB.
*/
function MatrixMultiplication(matrixA, matrixB) {
if (matrixA[0].length !== matrixB.length) {
return "Invalid Inputs, for this Question";
}
let rowSize = matrixA.length;
let columnSize = matrixB[0].length;
let commonSize = matrixB.length;
let result = [];
for (let i = 0; i < rowSize; i++) {
let row = [];
for (let j = 0; j < columnSize; j++) {
let sum = 0;
for (let k = 0; k < commonSize; k++) {
sum += matrixA[i][k] * matrixB[k][j];
}
row.push(sum);
}
result.push(row);
}
return result;
}
let MatA = [
[1, 2],
[3, 4],
];
let MatB = [
[5, 6],
[7, 8],
];
console.log(MatrixMultiplication(MatA, MatB));
//----------------------------------------------------------------
//* Search an Element in a Matrix
function SearchElementInMatrix(Matrix, target) {
for (let i = 0; i < Matrix.length; i++) {
for (let j = 0; j < Matrix[i].length; j++) {
if (Matrix[i][j] === target) {
return `Element is found at ${i} row, ${j} column`;
}
}
}
return "Element Not Found!";
}
let MatrixA = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
console.log(SearchElementInMatrix(MatrixA, 7));
// --------------------------------------------------------------
//* Matrix Transpose
/*
- If a matrix A has dimensions 𝑚×𝑛 (with 𝑚 rows and 𝑛 columns), its transpose 𝐴^𝑇 will have dimensions 𝑛×𝑚 (with 𝑛 rows and 𝑚 columns).
- In the transpose matrix, the element at position 𝐴[𝑖][𝑗] in the original matrix becomes 𝐴^𝑇[𝑗][𝑖]
*/
function MatrixTranspose(matrix) {
let rowSize = matrix.length;
let columnSize = matrix[0].length;
let TransposeMatrix = [];
for (let i = 0; i < columnSize; i++) {
let row = [];
for (let j = 0; j < rowSize; j++) {
row.push(matrix[j][i]);
}
TransposeMatrix.push(row);
}
return TransposeMatrix;
}
let Matrix = [
[1, 2, 3],
[4, 5, 6],
];
console.log(MatrixTranspose(Matrix));
================================================
FILE: DAY30/Questions.md
================================================
# DAY - 30
1. **Object Keys and Values**
Print all the keys and values of an object.
- **Input:**
```
let
```
- **Output:**
```
Keys: ["name", "age", "city"], Values: ["John", 25, "New York"]
```
2. **Merge Two Objects**
Combine the properties of two objects into one.
- **Input:**
```
let obj1 = { name: "John", age: 25 };
let obj2 = { city: "New York", country: "USA" };
```
- **Output:**
```
{ name: "John", age: 25, city: "New York", country: "USA" }
```
3. **Swap Keys and Values**
Create a new object where the keys and values are swapped.
- **Input:**
```
let obj = { name: "John", age: 25, city: "New York" };
```
- Output:
```
{ John: "name", 25: "age", "New York": "city" }
```
================================================
FILE: DAY30/Solutions.js
================================================
//* Object Keys and Values
let obj = { name: "John", age: 25, city: "New York" };
let obj1 = { name: "John", age: 25 };
let obj2 = { city: "New York", country: "USA" };
// ------------------------------------------------------------------------------------------
function PrintKeysValues(Obj) {
console.log("Keys : ", Object.keys(Obj));
console.log("Values: ", Object.values(Obj));
}
PrintKeysValues(obj);
// -------------------------------------------------------------
//* Merge two Objects
function MergeObjects(Obj1, Obj2) {
return Object.assign({}, Obj1, Obj2);
}
console.log(MergeObjects(obj1, obj2));
// -------------------------------------------------------------
//* Swap Keys and Values
function SwapKeysValues(Obj) {
let result = {};
for (key in Obj) {
result[Obj[key]] = key;
}
return result;
}
console.log(SwapKeysValues(obj));
================================================
FILE: DAY31/Questions.md
================================================
# DAY - 31
1. **Compare Two Objects**
Check if two objects have the same keys and values.
- **Input:**
```
let obj1 = { a: 1, b: 2, c: 3 };
let obj2 = { a: 1, b: 2, c: 3 };
```
- **Output:** true
2. **Convert an Array of Objects to a Single Object**
Create an object where each element of the array becomes a property.
- **Input:**
```
let arr = [
{ id: "a", value: 1 },
{ id: "b", value: 2 },
{ id: "c", value: 3 },
];
```
- **Output:**
```
{ a: 1, b: 2, c: 3 }
```
3. **Group Objects by a Property**
Group an array of objects by a specified property.
- **Input:**
```
let arr = [
{ category: "fruit", name: "apple" },
{ category: "fruit", name: "banana" },
{ category: "vegetable", name: "carrot" },
];
```
- **Output:**
```
{
fruit: [{ category: "fruit", name: "apple" }, { category: "fruit", name: "banana" }],
vegetable: [{ category: "vegetable", name: "carrot" }]
}
```
================================================
FILE: DAY31/Solutions.js
================================================
let obj1 = { a: 1, b: 2, c: 3 };
let obj2 = { a: 1, b: 2, c: 3 };
let arr1 = [
{ id: "a", value: 1 },
{ id: "b", value: 2 },
{ id: "c", value: 3 },
];
let arr2 = [
{ category: "fruit", name: "apple" },
{ category: "fruit", name: "banana" },
{ category: "vegetable", name: "carrot" },
];
// -----------------------------------------------------------------
//* Compare Two Objects
function CompareTwoObjects(Obj1, Obj2) {
if (Object.keys(Obj1).length !== Object.keys(Obj2)) {
return false;
}
for (let key in Obj1) {
if (Obj1[key] !== Obj2[key]) {
return false;
}
}
return true;
}
console.log(CompareTwoObjects(obj1, obj2));
// --------------------------------------------------------------------
//* Convert an Array of Objects to a Single Object
function ConvertToObject(arr) {
let result = {};
for (let i = 0; i < arr.length; i++) {
result[arr[i].id] = arr[i].value;
}
return result;
}
function ConvertToObject2(arr) {
let result = arr.map((item) => [item.id, item.value]);
// console.log(result);
result = Object.fromEntries(result);
return result;
}
console.log(ConvertToObject(arr1));
// console.log(ConvertToObject2(arr1));
// --------------------------------------------------------------------
//* Group Objects by Property
function GroupObjects(arr) {
let Grouped = {};
for (let i = 0; i < arr.length; i++) {
let key = arr[i].category;
if (!Grouped[key]) {
Grouped[key] = [];
}
Grouped[key].push(arr[i]);
}
return Grouped;
}
function GroupObjects2(arr) {
return arr.reduce((Grouped, item) => {
let key = item.category;
if (!Grouped[key]) {
Grouped[key] = [];
}
Grouped[key].push(item);
return Grouped;
}, {});
}
console.log(GroupObjects(arr2));
// console.log(GroupObjects2(arr2));
================================================
FILE: DAY32/Questions.md
================================================
# DAY - 32
1. **Clone an Object**
Create a shallow copy of an object.
- **Input:**
```
let obj = { name: "John", age: 25, city: "New York" };
```
- **Output:**
```
{ name: "John", age: 25, city: "New York" }
```
2. **Flatten a Nested Object**
Convert a deeply nested object into a single-level object.
- **Input:**
```
let obj = { a: 1, b: { c: 2, d: { e: 3 } } };
```
- **Output:**
```
{ a: 1, "b.c": 2, "b.d.e": 3 }
```
3. **Sum of N Natural Numbers using Recursion**
Write a Program to Find the Sum of N Natural Numbers using Recursion
- **Input:**
```
Enter a number: 5
```
- **Output:**
```
The sum of the first 5 natural numbers is: 15
```
================================================
FILE: DAY32/Solutions.js
================================================
let obj1 = { name: "John", age: 25, city: "New York" };
let obj2 = { a: 1, b: { c: 2, d: { e: 3 } } };
// -----------------------------------------------------------------
//* Clone an Object
function CloneObject(Obj) {
// using spread operator
let ObjCopy1 = { ...Obj };
// using Object.assign(target, obj)
let ObjCopy2 = Object.assign({}, Obj);
return ObjCopy2;
}
console.log(CloneObject(obj1));
// -----------------------------------------------------------------
//* Flatten a Nested Object
function FlattenNestedObject(Obj) {
let result = {};
let keysToProcess = Object.entries(Obj);
while (keysToProcess.length > 0) {
// get the first key value pair
let [currentkey, value] = keysToProcess.shift();
if (typeof value === "object" && value !== null) {
// If the value is an object, iterate over its keys
for (let subkey in value) {
let newkey = `${currentkey}.${subkey}`; // flatten the key
keysToProcess.push([newkey, value[subkey]]);
}
} else {
// If it's not an object, add it to the result
result[currentkey] = value;
}
}
return result;
}
console.log(FlattenNestedObject(obj2));
// ----------------------------------------------------------------
//* Sum of N Natural Numbers using Recursion
function SumOfNRecursion(N) {
// Base condition
if (N === 1) {
return 1;
}
// recurrence relation
return N + SumOfNRecursion(N - 1);
}
console.log(SumOfNRecursion(5));
================================================
FILE: DAY33/Questions.md
================================================
# DAY - 33
1. **Factorial of a Number Using Recursion**
The factorial of a number is the product of all positive integers less than or equal to the number.
- **Input: n = 5**
- **Output: 120 (since 5!=5×4×3×2×1)**
2. **Calculates the Power of a Number Using Recursion**
Write a Program that Calculates the Power of a Number Using Recursion
- **Input: base = 2, exponent = 3**
- **Output: 8 (since 2^3 => 2 x 2 x 2 = 8)**
3. **Fibonacci Series Using Recursion**
The Fibonacci series is a sequence where each number is the sum of the two preceding ones. The sequence starts with 0 and 1. This program calculates the nth Fibonacci number recursively.
- **Input: n = 5**
- **Output: 0, 1, 1, 2, 3**
================================================
FILE: DAY33/Solutions.js
================================================
//* Factorial of a Number Using Recursion
function FactorialRecursion(N) {
if (N === 1) {
return 1;
}
return N * FactorialRecursion(N - 1);
}
console.log(FactorialRecursion(5));
// --------------------------------------------------------------------
//* Calculates the Power of a Number Using Recursion
function PowerOfNum(base, exponent) {
if (exponent === 0) {
return 1;
}
return base * PowerOfNum(base, exponent - 1);
}
console.log(PowerOfNum(2, 3));
// ---------------------------------------------------------------------
//* Fibonacci Series Using Recursion
function FibonacciSeriesRecursion(n, series = []) {
// Base case: Series starts with 0
if (n == 0) {
return [0];
}
// Base case: Series for n = 1 is [0, 1]
if (n == 1) {
return [0, 1];
}
let prevSeries = FibonacciSeriesRecursion(n - 1, series);
let nextNum =
prevSeries[prevSeries.length - 1] + prevSeries[prevSeries.length - 2];
prevSeries.push(nextNum);
return prevSeries;
}
console.log(FibonacciSeriesRecursion(5));
================================================
FILE: DAY34/Questions.md
================================================
# DAY - 34
1. **Check if a String is a Palindrome**
Check whether a given string is a palindrome using recursion.
- **Input: str = "radar"**
- **Output: true**
2. **Find GCD of Two Numbers**
Calculate the greatest common divisor (GCD) of two numbers using recursion.
- **Input: a = 56, b = 98**
- **Output: 14**
3. **Binary Representation of a Number**
Find the binary representation of a given number using recursion.
- **Input: num = 10**
- **Output: "1010"**
================================================
FILE: DAY34/Solutions.js
================================================
//* Check if a String is a Palindrome
function checkPlaindromeRecursion(str, start = 0, end = str.length - 1) {
// base case : Single character or empty string
if (start >= end) {
return "true";
}
if (str.charAt(start) !== str.charAt(end)) {
return false;
}
return checkPlaindromeRecursion(str, start + 1, end - 1);
}
console.log(checkPlaindromeRecursion("radar"));
// ----------------------------------------------------------------------
//* Find GCD of Two Numbers
function FindGCDRecursion(num1, num2) {
if (num2 == 0) {
return num1;
}
return FindGCDRecursion(num2, num1 % num2);
}
console.log(FindGCDRecursion(56, 98));
// ---------------------------------------------------------------------
//* Binary Representation of a Number
function BinaryRepresentationRecursion(n) {
// base condition
if (n === 0) {
return "";
}
let quotient = Math.floor(n / 2);
let result = n % 2;
return BinaryRepresentationRecursion(quotient) + result;
}
console.log(BinaryRepresentationRecursion(10));
================================================
FILE: readme.md
================================================
# LogicBuilding101
- Welcome to **LogicBuilding101**, a curated collection of **101+1 must-do problems** designed to build your programming logic from scratch.
- This repository serves as a foundational resource for anyone who wants to sharpen their problem-solving skills before diving into Data Structures and Algorithms (DSA).
## Overview
- This repository is structured to take you on a journey from the basics of programming to slightly advanced concepts, focusing on logic-building exercises.
- Over **34 days**, with a daily commitment of solving 3 problems, you can develop a strong programming foundation.
### Problem Categories
1. **Basic Math Problems**
2. **Basic Patterns**
3. **Intermediate Math Problems**
4. **Medium Patterns**
5. **Arrays**
6. **Matrix**
7. **Strings**
8. **Objects**
9. **Basic Recursion**
### Why LogicBuilding101?
- Develop **core programming skills**.
- Understand basic and intermediate concepts of programming.
- Lay a strong foundation for **DSA preparation**.
- Practice a diverse set of problems from simple **math** to **recursion**.
---
## Repository Structure
The repository is divided into **daily problem sets**, with each day containing 3 problems:
```
LogicBuilding101/
├── Day01/
│ ├── Questions.md
│ ├── Solutions.js
├── Day02/
│ ├── Questions.md
│ ├── Solutions.js
...
├── Day34/
│ ├── Questions.md
│ ├── Solutions.js
```
### Questions File Structure
Each Questions file contains:
- **Problem Name**: The title of the problem.
- **Description**: A detailed explanation of the problem.
- **Input/Output**: Sample input and output examples.
---
## How to Use This Repo
1. Clone the repository:
```bash
git clone https://github.com/upendhar10/LogicBuilding101.git
```
2. Start with Day 1 and progress at your own pace.
3. Solve the problems in your preferred programming language.
4. Check your logic and solutions with the provided examples.
---
## Acknowledgments
- A huge thanks to the programming community for inspiring this project. Let's build a strong foundation together!
- If you found this repo valuable, don't forget to **STAR** this repo. Thanks in advance!
---
## License
This project is licensed under the MIT License. Feel free to use and share!
gitextract_uj61cvru/ ├── .gitignore ├── DAY01/ │ ├── Questions.md │ └── Solutions.js ├── DAY02/ │ ├── Questions.md │ └── Solutions.js ├── DAY03/ │ ├── Questions.md │ └── Solutions.js ├── DAY04/ │ ├── Questions.md │ └── Solutions.js ├── DAY05/ │ ├── Questions.md │ └── Solutions.js ├── DAY06/ │ ├── Questions.md │ └── Solutions.js ├── DAY07/ │ ├── Questions.md │ └── Solutions.js ├── DAY08/ │ ├── Questions.md │ └── Solutions.js ├── DAY09/ │ ├── Questions.md │ └── Solutions.js ├── DAY10/ │ ├── Questions.md │ └── Solutions.js ├── DAY11/ │ ├── Questions.md │ └── Solutions.js ├── DAY12/ │ ├── Questions.md │ └── Solutions.js ├── DAY13/ │ ├── Questions.md │ └── Solutions.js ├── DAY14/ │ ├── Questions.md │ └── Solutions.js ├── DAY15/ │ ├── Questions.md │ └── Solutions.js ├── DAY16/ │ ├── Questions.md │ └── Solutions.js ├── DAY17/ │ ├── Questions.md │ ├── Solutions.js │ └── notes.md ├── DAY18/ │ ├── Questions.md │ └── Solutions.js ├── DAY19/ │ ├── Questions.md │ └── Solutions.js ├── DAY20/ │ ├── Questions.md │ └── Solutions.js ├── DAY21/ │ ├── Questions.md │ └── Solutions.js ├── DAY22/ │ ├── Questions.md │ └── Solutions.js ├── DAY23/ │ ├── Questions.md │ └── Solutions.js ├── DAY24/ │ ├── Questions.md │ └── Solutions.js ├── DAY25/ │ ├── Questions.md │ └── Solutions.js ├── DAY26/ │ ├── Questions.md │ └── Solutions.js ├── DAY27/ │ ├── Questions.md │ └── Solutions.js ├── DAY28/ │ ├── Questions.md │ └── Solutions.js ├── DAY29/ │ ├── Questions.md │ └── Solutions.js ├── DAY30/ │ ├── Questions.md │ └── Solutions.js ├── DAY31/ │ ├── Questions.md │ └── Solutions.js ├── DAY32/ │ ├── Questions.md │ └── Solutions.js ├── DAY33/ │ ├── Questions.md │ └── Solutions.js ├── DAY34/ │ ├── Questions.md │ └── Solutions.js └── readme.md
SYMBOL INDEX (114 symbols across 34 files)
FILE: DAY01/Solutions.js
function findMax (line 34) | function findMax(num1, num2) {
FILE: DAY02/Solutions.js
function CheckEvenOdd (line 5) | function CheckEvenOdd(num) {
function divisibleBy5 (line 21) | function divisibleBy5(num) {
function multipleOf7 (line 36) | function multipleOf7(num) {
FILE: DAY03/Solutions.js
function findSquareAndCube (line 5) | function findSquareAndCube(num) {
function AreaOfCircleAndTriangle (line 25) | function AreaOfCircleAndTriangle(radius, base, height) {
function circleArea (line 34) | function circleArea(radius) {
function triangleArea (line 39) | function triangleArea(base, height) {
function findQuotientAndRemainder (line 53) | function findQuotientAndRemainder(divisor, dividend) {
FILE: DAY04/Solutions.js
function PrintTable (line 4) | function PrintTable(num) {
function Calculator (line 20) | function Calculator() {
function PrintReverseNum (line 48) | function PrintReverseNum(num) {
FILE: DAY05/Solutions.js
function findSumOfDigits (line 5) | function findSumOfDigits(num) {
function checkCharacter (line 23) | function checkCharacter(char) {
function findASCIIValue (line 45) | function findASCIIValue(val) {
FILE: DAY06/Solutions.js
function Pattern1 (line 3) | function Pattern1(n) {
function pattern2 (line 21) | function pattern2(n) {
function Pattern3 (line 38) | function Pattern3(n) {
FILE: DAY07/Solutions.js
function Pattern1 (line 3) | function Pattern1(n) {
function Pattern2 (line 19) | function Pattern2(n) {
function Pattern3 (line 41) | function Pattern3(n) {
FILE: DAY08/Solutions.js
function Pattern1 (line 3) | function Pattern1(n) {
function Pattern2 (line 19) | function Pattern2(n) {
function Pattern3 (line 35) | function Pattern3(n) {
FILE: DAY09/Solutions.js
function Pattern1 (line 3) | function Pattern1(n) {
function Pattern2 (line 25) | function Pattern2(n) {
function Pattern3 (line 41) | function Pattern3(n) {
FILE: DAY10/Solutions.js
function Pattern1 (line 3) | function Pattern1(n) {
function Pattern2 (line 18) | function Pattern2(n) {
function SwapTwoNumbers1 (line 51) | function SwapTwoNumbers1(num1, num2) {
function SwapTwoNumbers2 (line 66) | function SwapTwoNumbers2(num1, num2) {
FILE: DAY11/Solutions.js
function LargestAmongThreeNums (line 3) | function LargestAmongThreeNums(num1, num2, num3) {
function isLeapYear (line 25) | function isLeapYear(year) {
function SumOfFirstNnaturalNums (line 39) | function SumOfFirstNnaturalNums(n) {
FILE: DAY12/Solutions.js
function FindFactorial (line 3) | function FindFactorial(n) {
function PrintFibonacciSeries (line 19) | function PrintFibonacciSeries(n) {
function findHCF (line 42) | function findHCF(num1, num2) {
FILE: DAY13/Solutions.js
function findLCM (line 3) | function findLCM(num1, num2) {
function findPowerManual (line 28) | function findPowerManual(base, expo) {
function findPowerBuiltIn (line 36) | function findPowerBuiltIn(base, expo) {
function DigitToWord (line 47) | function DigitToWord(num) {
FILE: DAY14/Solutions.js
function NumToWordsReverse (line 3) | function NumToWordsReverse(num) {
function PrintFactors (line 64) | function PrintFactors(n) {
function ValidAmstrong (line 82) | function ValidAmstrong(num) {
FILE: DAY15/Solutions.js
function ValidPrime (line 3) | function ValidPrime(num) {
function PrimeNumsInRange (line 30) | function PrimeNumsInRange(start, end) {
function PrintFactorialSeries1 (line 53) | function PrintFactorialSeries1(num) {
function PrintFactorialSeries2 (line 65) | function PrintFactorialSeries2(num) {
FILE: DAY16/Solutions.js
function ValidPalindrome (line 3) | function ValidPalindrome(num) {
function isPrime (line 32) | function isPrime(n) {
function SumOfTwoPrimes (line 39) | function SumOfTwoPrimes(N) {
function PrintNumbers (line 63) | function PrintNumbers() {
function PrintAlphabets (line 72) | function PrintAlphabets() {
FILE: DAY17/Solutions.js
function binaryToDecimal (line 4) | function binaryToDecimal(binary) {
function decimalToBinary (line 19) | function decimalToBinary(decimal) {
function PrintPattern1 (line 46) | function PrintPattern1(n) {
function PrintPattern2 (line 70) | function PrintPattern2(n) {
FILE: DAY18/Solutions.js
function PrintPattern1 (line 3) | function PrintPattern1(n) {
function PrintPattern1Optimized (line 41) | function PrintPattern1Optimized(n) {
function PrintPattern2 (line 66) | function PrintPattern2(n) {
function PrintPattern3 (line 108) | function PrintPattern3(n) {
FILE: DAY19/Solutions.js
function PrintPattern1 (line 3) | function PrintPattern1(n) {
function PrintPattern2 (line 24) | function PrintPattern2(n) {
function PrintPattern3 (line 48) | function PrintPattern3(n) {
FILE: DAY20/Solutions.js
function PrintPattern1 (line 3) | function PrintPattern1(n) {
function PrintPattern2 (line 47) | function PrintPattern2(n) {
function PrintPattern3 (line 74) | function PrintPattern3(n) {
FILE: DAY21/Solutions.js
function PerfectNum (line 3) | function PerfectNum(n) {
function isPrime (line 26) | function isPrime(n) {
function LargestPrimeFactor (line 34) | function LargestPrimeFactor(num) {
function SumSeries (line 57) | function SumSeries(n) {
FILE: DAY22/Solutions.js
function SortAscendingOrder (line 10) | function SortAscendingOrder(arr) {
function SortDescendingOrder (line 24) | function SortDescendingOrder(arr) {
function LongConsequence1 (line 45) | function LongConsequence1(arr) {
function MostFrequentElement (line 65) | function MostFrequentElement(arr) {
FILE: DAY23/Solutions.js
function FindMissingNum (line 3) | function FindMissingNum(arr) {
function FindMajorityElement (line 23) | function FindMajorityElement(arr) {
function ReverseArray (line 57) | function ReverseArray(arr) {
FILE: DAY24/Solutions.js
function FindSecondLargest (line 3) | function FindSecondLargest(arr) {
function RemoveDuplicates (line 29) | function RemoveDuplicates(arr) {
function MoveZeroEnd (line 48) | function MoveZeroEnd(arr) {
FILE: DAY25/Solutions.js
function FindFrequencyofElements (line 3) | function FindFrequencyofElements(arr) {
function checkPalindromString (line 23) | function checkPalindromString(str) {
function FindWordsCount (line 49) | function FindWordsCount(str) {
FILE: DAY26/Solutions.js
function LongestWord (line 3) | function LongestWord(sentence) {
function NonRepeatingChar (line 24) | function NonRepeatingChar(str) {
function PrintAllSubstrings (line 49) | function PrintAllSubstrings(str) {
function PrintAllSubstrings2 (line 61) | function PrintAllSubstrings2(str) {
FILE: DAY27/Solutions.js
function CheckAnagrams (line 11) | function CheckAnagrams(str1, str2) {
function ValidRotationStrings (line 35) | function ValidRotationStrings(str1, str2) {
function RemoveNonAlphabets (line 53) | function RemoveNonAlphabets(str) {
FILE: DAY28/Solutions.js
function FindDuplicatesChars (line 3) | function FindDuplicatesChars(str) {
function CountVowelsAndConsonants (line 29) | function CountVowelsAndConsonants(str) {
function MatrixAddition (line 63) | function MatrixAddition(matrixA, matrixB) {
FILE: DAY29/Solutions.js
function MatrixMultiplication (line 9) | function MatrixMultiplication(matrixA, matrixB) {
function SearchElementInMatrix (line 53) | function SearchElementInMatrix(Matrix, target) {
function MatrixTranspose (line 81) | function MatrixTranspose(matrix) {
FILE: DAY30/Solutions.js
function PrintKeysValues (line 9) | function PrintKeysValues(Obj) {
function MergeObjects (line 20) | function MergeObjects(Obj1, Obj2) {
function SwapKeysValues (line 30) | function SwapKeysValues(Obj) {
FILE: DAY31/Solutions.js
function CompareTwoObjects (line 19) | function CompareTwoObjects(Obj1, Obj2) {
function ConvertToObject (line 38) | function ConvertToObject(arr) {
function ConvertToObject2 (line 48) | function ConvertToObject2(arr) {
function GroupObjects (line 65) | function GroupObjects(arr) {
function GroupObjects2 (line 80) | function GroupObjects2(arr) {
FILE: DAY32/Solutions.js
function CloneObject (line 8) | function CloneObject(Obj) {
function FlattenNestedObject (line 24) | function FlattenNestedObject(Obj) {
function SumOfNRecursion (line 54) | function SumOfNRecursion(N) {
FILE: DAY33/Solutions.js
function FactorialRecursion (line 3) | function FactorialRecursion(N) {
function PowerOfNum (line 17) | function PowerOfNum(base, exponent) {
function FibonacciSeriesRecursion (line 31) | function FibonacciSeriesRecursion(n, series = []) {
FILE: DAY34/Solutions.js
function checkPlaindromeRecursion (line 3) | function checkPlaindromeRecursion(str, start = 0, end = str.length - 1) {
function FindGCDRecursion (line 22) | function FindGCDRecursion(num1, num2) {
function BinaryRepresentationRecursion (line 36) | function BinaryRepresentationRecursion(n) {
Condensed preview — 71 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (83K chars).
[
{
"path": ".gitignore",
"chars": 5,
"preview": ".git/"
},
{
"path": "DAY01/Questions.md",
"chars": 933,
"preview": "# DAY - 01\n\n1. **Program to Print Integer Numbers Entered by the User:**\n\n Write a program where the user is asked to "
},
{
"path": "DAY01/Solutions.js",
"chars": 1823,
"preview": "// # Program to Print Integer Numbers Entered by the User:\n\n/*\n - Since, NaN (Not-a-Number) is a special value in Jav"
},
{
"path": "DAY02/Questions.md",
"chars": 1477,
"preview": "# DAY - 02\n\n1. **Program to Check Whether the Number is Odd or Even:**\n\n Write a program that checks whether a number "
},
{
"path": "DAY02/Solutions.js",
"chars": 1159,
"preview": "let num = parseInt(prompt(\"Enter a number: \", 0));\n\n//* Program to Check Whether the Number is Odd or Even:\n\nfunction Ch"
},
{
"path": "DAY03/Questions.md",
"chars": 933,
"preview": "# DAY - 03\n\n1. **Program to Calculate the Square and Cube of a Number:**\n\n Write a program where the user enters a num"
},
{
"path": "DAY03/Solutions.js",
"chars": 2039,
"preview": "// # Program to Calculate the Square and Cube of a Number\n\nlet num = parseInt(prompt(\"Enter a number\", 0));\nfindSquareAn"
},
{
"path": "DAY04/Questions.md",
"chars": 911,
"preview": "# DAY - 04\n\n1. **Print the Multiplication Table of a Given Number:**\n\n Write a program where the user enters a number,"
},
{
"path": "DAY04/Solutions.js",
"chars": 1362,
"preview": "//* Print the Multiplication Table of a Given Number\n\nlet number = 5;\nfunction PrintTable(num) {\n for (let i = 1; i <= "
},
{
"path": "DAY05/Questions.md",
"chars": 792,
"preview": "# DAY - 05\n\n1. **Calculate the Sum of Digits of a Given Number:**\n\n Write a program that calculates the sum of the dig"
},
{
"path": "DAY05/Solutions.js",
"chars": 1210,
"preview": "//* Calculate the Sum of Digits of a Given Number\n\nlet number = 1234;\n\nfunction findSumOfDigits(num) {\n let sum = 0;\n "
},
{
"path": "DAY06/Questions.md",
"chars": 259,
"preview": "# DAY - 06\n\n## Pattern 1: Sqaure\n\n```\n* * * * *\n* * * * *\n* * * * *\n* * * * *\n* * * * *\n```\n\n## Pattern 2: Right-angled "
},
{
"path": "DAY06/Solutions.js",
"chars": 1023,
"preview": "//* Pattern - 1\n\nfunction Pattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \"\";\n for (let j = 1; j "
},
{
"path": "DAY07/Questions.md",
"chars": 311,
"preview": "# DAY - 07\n\n## Pattern 1: Inverted Right-angled triangle\n\n```\n* * * * *\n* * * *\n* * *\n* *\n*\n```\n\n## Pattern 2: traingle\n"
},
{
"path": "DAY07/Solutions.js",
"chars": 1186,
"preview": "//* Pattern-1 :\n\nfunction Pattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \" \";\n for (let j = n; j"
},
{
"path": "DAY08/Questions.md",
"chars": 147,
"preview": "# DAY - 08\n\n## Pattern 7:\n\n1\n1 2\n1 2 3\n1 2 3 4\n1 2 3 4 5\n\n## Pattern 8\n\n1\n2 2\n3 3 3\n4 4 4 4\n5 5 5 5 5\n\n## Pattern 9\n\n1 2"
},
{
"path": "DAY08/Solutions.js",
"chars": 812,
"preview": "//* Pattern - 1\n\nfunction Pattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \" \";\n for (let j = 1; j"
},
{
"path": "DAY09/Questions.md",
"chars": 193,
"preview": "## Pattern 1\n\n```\n1 1\n1 2 2 1\n1 2 3 3 2 1\n1 2 3 4 4 3 2 1\n\n```\n\n## Pattern 2\n\n```\nA\nA B\nA B C\nA "
},
{
"path": "DAY09/Solutions.js",
"chars": 1049,
"preview": "//* Pattern - 1\n\nfunction Pattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \" \";\n for (let j = 1; j"
},
{
"path": "DAY10/Questions.md",
"chars": 404,
"preview": "## Pattern 1\n\n```\nA\nB B\nC C C\nD D D D\nE E E E E\n```\n\n## Pattern 2\n\n```\n A\n A B A\n A B C B A\nA B C D C B A\n```\n\n"
},
{
"path": "DAY10/Solutions.js",
"chars": 1540,
"preview": "//* Pattern - 1\n\nfunction Pattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \" \";\n for (let j = 1; j"
},
{
"path": "DAY11/Questions.md",
"chars": 908,
"preview": "# DAY - 11\n\n1. **Write a Program to Find the Largest Number Among Three Numbers:**\n\n Write a program where the user en"
},
{
"path": "DAY11/Solutions.js",
"chars": 1100,
"preview": "//* Program to Find the Largest Number Among Three Numbers\n\nfunction LargestAmongThreeNums(num1, num2, num3) {\n if (num"
},
{
"path": "DAY12/Questions.md",
"chars": 833,
"preview": "# DAY - 12\n\n1. **Factorial of a Number Using a For Loop:**\n\n Write a program to calculate the factorial of a number en"
},
{
"path": "DAY12/Solutions.js",
"chars": 1004,
"preview": "//* Factorial of a Number Using a For Loop\n\nfunction FindFactorial(n) {\n let fact = 1;\n\n for (let i = 1; i <= n; i++)"
},
{
"path": "DAY13/Questions.md",
"chars": 963,
"preview": "# DAY - 13\n\n1. **Write a Program to Find the LCM of Two Numbers:**\n\n Write a program where the user enters two numbers"
},
{
"path": "DAY13/Solutions.js",
"chars": 1467,
"preview": "//* Write a Program to Find the LCM of Two Numbers\n\nfunction findLCM(num1, num2) {\n if (num1 === 0 || num2 === 0) {\n "
},
{
"path": "DAY14/Questions.md",
"chars": 747,
"preview": "# DAY - 14\n\n1. **Print Numbers in Words in Reverse Order Using a Switch Case:**\n\n Write a program that takes an intege"
},
{
"path": "DAY14/Solutions.js",
"chars": 1955,
"preview": "//* Print Numbers in Words in Reverse Order Using a Switch Case\n\nfunction NumToWordsReverse(num) {\n if (isNaN(num)) {\n"
},
{
"path": "DAY15/Questions.md",
"chars": 804,
"preview": "# DAY - 15\n\n1. **Check Whether a Number is Prime or Not:**\n\n Write a program that checks if a number entered by the us"
},
{
"path": "DAY15/Solutions.js",
"chars": 1387,
"preview": "//* Check Whether a Number is Prime or Not\n\nfunction ValidPrime(num) {\n if (num <= 1) {\n return `${num} is Not Prim"
},
{
"path": "DAY16/Questions.md",
"chars": 880,
"preview": "# DAY - 16\n\n1. **Write a Program to Check Whether a Number is a Palindrome:**\n\n Write a program to determine if a numb"
},
{
"path": "DAY16/Solutions.js",
"chars": 1889,
"preview": "//* Write a Program to Check Whether a Number is a Palindrome\n\nfunction ValidPalindrome(num) {\n if (isNaN(num)) {\n "
},
{
"path": "DAY17/Questions.md",
"chars": 679,
"preview": "# DAY - 17\n\n1. **Write a Program to Convert Binary Numbers to Decimal and Vice Versa Manually:**\n\n Write a program tha"
},
{
"path": "DAY17/Solutions.js",
"chars": 2017,
"preview": "//* Program to Convert Binary Numbers to Decimal and Vice Versa Manually:\n\n// Function to convert Binary to Decimal\nfunc"
},
{
"path": "DAY17/notes.md",
"chars": 976,
"preview": "## Binary to Decimal Conversion:\n\n### Binary Number:\n\n- A binary number is made up of 0's and 1's and uses base 2.\n- To "
},
{
"path": "DAY18/Questions.md",
"chars": 507,
"preview": "# DAY - 18\n\n**Pattern - 1**\n\n```\n* *\n* * * *\n* * * * * *\n* * * * * * * *\n* * * *"
},
{
"path": "DAY18/Solutions.js",
"chars": 2217,
"preview": "//* Pattern - 1\n\nfunction PrintPattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \"\";\n\n for (let j ="
},
{
"path": "DAY19/Questions.md",
"chars": 241,
"preview": "# DAY - 19\n\n## Pattern 1:\n\n```\n1\n0 1\n1 0 1\n0 1 0 1\n1 0 1 0 1\n```\n\n## Pattern 2:\n\n```\n4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2"
},
{
"path": "DAY19/Solutions.js",
"chars": 1291,
"preview": "//* Pattern - 1\n\nfunction PrintPattern1(n) {\n for (let i = 1; i <= n; i++) {\n let rowPattern = \"\";\n\n for (let j "
},
{
"path": "DAY20/Questions.md",
"chars": 181,
"preview": "# DAY - 20\n\n## Pattern 1\n\n```\n *\n * *\n * *\n* *\n * *\n * *\n *\n```\n\n## Pattern 2\n\n```\n 1\n 1 2 1\n1 2 3 2 1"
},
{
"path": "DAY20/Solutions.js",
"chars": 1668,
"preview": "//* Pattern - 1\n\nfunction PrintPattern1(n) {\n // Top half of the diamond\n for (let i = 1; i <= n; i++) {\n let rowPa"
},
{
"path": "DAY21/Questions.md",
"chars": 613,
"preview": "# DAY - 21\n\n1. **Perfect Number**\n Write a program to determine if a number is a perfect number.\n\n - **Input:** **`n"
},
{
"path": "DAY21/Solutions.js",
"chars": 1303,
"preview": "//* Perfect Number\n\nfunction PerfectNum(n) {\n if (n <= 0) {\n return `Input must be Posivitve Number`;\n }\n\n let sum"
},
{
"path": "DAY22/Questions.md",
"chars": 706,
"preview": "# DAY - 22\n\n1. **Print the Array in Sorted Order (Ascending and Descending):**\n\n Write a program to sort an array in a"
},
{
"path": "DAY22/Solutions.js",
"chars": 1864,
"preview": "//* Print the Array in Sorted Order (Ascending and Descending)\n\n/*\n Built-In Methods\nAscending Order : arr.sort((a, b)"
},
{
"path": "DAY23/Questions.md",
"chars": 591,
"preview": "# DAY - 23\n\n1. **Find the Missing Number in an Array**\n\n - Given an array of numbers from 1 to n with one number missi"
},
{
"path": "DAY23/Solutions.js",
"chars": 1393,
"preview": "//* Missing Number\n\nfunction FindMissingNum(arr) {\n let MissingNum = null;\n\n let n = arr.length + 1;\n\n let TotalSum ="
},
{
"path": "DAY24/Questions.md",
"chars": 639,
"preview": "# DAY - 24\n\n1. **Find the Second Largest Element in an Array**\n\n - Find the second largest element in the array.\n "
},
{
"path": "DAY24/Solutions.js",
"chars": 1382,
"preview": "//* Find the Second Largest Element in an Array\n\nfunction FindSecondLargest(arr) {\n if (arr.length < 2) {\n return \""
},
{
"path": "DAY25/Questions.md",
"chars": 502,
"preview": "# DAY - 25\n\n1. **Find the Frequency of Each Element in an Array**\n\n Calculate the frequency of each element in the a"
},
{
"path": "DAY25/Solutions.js",
"chars": 1114,
"preview": "//* Find the Frequency of Each Element in an Array\n\nfunction FindFrequencyofElements(arr) {\n let frequency = {};\n\n for"
},
{
"path": "DAY26/Questions.md",
"chars": 481,
"preview": "# DAY - 27\n\n1. **Longest Word in a Sentence**\n\n Find the longest word in a given sentence.\n\n - **Input: \"The quick b"
},
{
"path": "DAY26/Solutions.js",
"chars": 1632,
"preview": "//* Longest Word in a Sentence\n\nfunction LongestWord(sentence) {\n let sentenceArr = sentence.split(\" \");\n\n let MaxCou"
},
{
"path": "DAY27/Questions.md",
"chars": 517,
"preview": "# DAY 27\n\n1. **Check Anagrams**\n\n Determine if two strings are anagrams of each other.\n\n - **Input: \"listen\", \"silen"
},
{
"path": "DAY27/Solutions.js",
"chars": 1539,
"preview": "//* Check Anagrams\n\n/*\n - An anagram string refers to a pair of strings that contain the exact same characters in th"
},
{
"path": "DAY28/Questions.md",
"chars": 553,
"preview": "# DAY - 28\n\n1. **Find Duplicate Characters in a String**\n\n Identify all characters that appear more than once in a str"
},
{
"path": "DAY28/Solutions.js",
"chars": 1875,
"preview": "//* Find Duplicate Characters in a String\n\nfunction FindDuplicatesChars(str) {\n let result = [];\n\n for (let i = 0; i <"
},
{
"path": "DAY29/Questions.md",
"chars": 773,
"preview": "# DAY - 29\n\n1. **Matrix Multiplication**\n\n Multiply two matrices if the number of columns in the first matrix equals t"
},
{
"path": "DAY29/Solutions.js",
"chars": 2188,
"preview": "//* Matrix Multipication\n\n/*\n # Matrix Multiplication Rules:\n - The no.of rows in the matrixA should be equal to t"
},
{
"path": "DAY30/Questions.md",
"chars": 750,
"preview": "# DAY - 30\n\n1. **Object Keys and Values**\n\n Print all the keys and values of an object.\n\n- **Input:**\n\n ```\n let\n `"
},
{
"path": "DAY30/Solutions.js",
"chars": 874,
"preview": "//* Object Keys and Values\n\nlet obj = { name: \"John\", age: 25, city: \"New York\" };\nlet obj1 = { name: \"John\", age: 25 };"
},
{
"path": "DAY31/Questions.md",
"chars": 956,
"preview": "# DAY - 31\n\n1. **Compare Two Objects**\n\n Check if two objects have the same keys and values.\n\n- **Input:**\n\n ```\n le"
},
{
"path": "DAY31/Solutions.js",
"chars": 1838,
"preview": "let obj1 = { a: 1, b: 2, c: 3 };\nlet obj2 = { a: 1, b: 2, c: 3 };\n\nlet arr1 = [\n { id: \"a\", value: 1 },\n { id: \"b\", va"
},
{
"path": "DAY32/Questions.md",
"chars": 775,
"preview": "# DAY - 32\n\n1. **Clone an Object**\n\n Create a shallow copy of an object.\n\n - **Input:**\n\n ```\n let obj = { "
},
{
"path": "DAY32/Solutions.js",
"chars": 1490,
"preview": "let obj1 = { name: \"John\", age: 25, city: \"New York\" };\n\nlet obj2 = { a: 1, b: { c: 2, d: { e: 3 } } };\n\n// ------------"
},
{
"path": "DAY33/Questions.md",
"chars": 731,
"preview": "# DAY - 33\n\n1. **Factorial of a Number Using Recursion**\n\n The factorial of a number is the product of all positive in"
},
{
"path": "DAY33/Solutions.js",
"chars": 1053,
"preview": "//* Factorial of a Number Using Recursion\n\nfunction FactorialRecursion(N) {\n if (N === 1) {\n return 1;\n }\n\n retur"
},
{
"path": "DAY34/Questions.md",
"chars": 498,
"preview": "# DAY - 34\n\n1. **Check if a String is a Palindrome**\n\n Check whether a given string is a palindrome using recursion.\n\n"
},
{
"path": "DAY34/Solutions.js",
"chars": 1052,
"preview": "//* Check if a String is a Palindrome\n\nfunction checkPlaindromeRecursion(str, start = 0, end = str.length - 1) {\n // b"
},
{
"path": "readme.md",
"chars": 2261,
"preview": "# LogicBuilding101\n\n- Welcome to **LogicBuilding101**, a curated collection of **101+1 must-do problems** designed to bu"
}
]
About this extraction
This page contains the full source code of the Upendhar10/LogicBuilding101 GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 71 files (73.5 KB), approximately 23.3k tokens, and a symbol index with 114 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.