Skip to content

Commit 2a4978e

Browse files
new problems has been solved here
1 parent 4b239e7 commit 2a4978e

File tree

8 files changed

+161
-0
lines changed

8 files changed

+161
-0
lines changed

C. Array/big-name.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* problem-19
2+
Find the friend with the biggest name.
3+
const names = ['rahim', 'robin', 'rafi', 'ron', 'rashed'];
4+
*/
5+
6+
const names = ['rahim', 'robin', 'rafi', 'ron', 'rashed'];
7+
let bigName = names[0];
8+
for (let i = 0; i < names.length; i++) {
9+
if (names[i].length > bigName.length) {
10+
bigName = names[i];
11+
}
12+
}
13+
console.log(bigName);

C. Array/height-number.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Problem-17
2+
3+
Find the height number in the array below.
4+
const numbers = [167, 190, 120, 165, 137];
5+
*/
6+
7+
const numbers = [167, 190, 120, 165, 137];
8+
let maxNumber = numbers[0];
9+
for (let i = 0; i < numbers.length; i++) {
10+
if (numbers[i] > maxNumber) {
11+
maxNumber = numbers[i]
12+
}
13+
}
14+
console.log("This is height Number = ", maxNumber);

C. Array/lowest-number.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Problem-16
2+
3+
Find the lowest number in the array below.
4+
const numbers = [167, 190, 120, 165, 137];
5+
*/
6+
7+
const numbers = [167, 190, 120, 165, 137];
8+
let minNumber = numbers[0];
9+
for (let i = 0; i < numbers.length; i++) {
10+
if (numbers[i] < minNumber) {
11+
minNumber = numbers[i]
12+
}
13+
}
14+
console.log("This is lowest Number = ", minNumber);

C. Array/small-name.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* problem-18
2+
Find the friend with the smallest name.
3+
const names = ['rahim', 'robin', 'rafi', 'ron', 'rashed'];
4+
*/
5+
const names = ['rahim', 'robin', 'rafi', 'ron', 'rashed'];
6+
let shortName = names[0];
7+
for (let i = 0; i < names.length; i++) {
8+
if (names[i].length < shortName.length) {
9+
shortName = names[i]
10+
}
11+
}
12+
console.log(shortName);

D. Loop/Array-loop/even-number.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Problem-2
2+
3+
Write a JavaScript code to get the even numbers from an array using any looping technique.
4+
5+
Input: const numbers = [12, 98, 5, 41, 23, 78, 46];
6+
7+
Output: [12, 98, 76, 46]
8+
*/
9+
10+
11+
const numbers = [12, 98, 5, 41, 23, 78, 46];
12+
13+
// Solution-1 by using for loop
14+
let evenNum = [];
15+
for (let i = 0; i < numbers.length; i++) {
16+
if (numbers[i] % 2 === 0) {
17+
evenNum.push(numbers[i]);
18+
}
19+
}
20+
console.log(evenNum);
21+
22+
23+
// Solution-2 by using While loop
24+
let evenNumbers = [];
25+
let j = 0;
26+
while (j < numbers.length) {
27+
if (numbers[j] % 2 === 0) {
28+
evenNumbers.push(numbers[j]);
29+
30+
}
31+
j++;
32+
}
33+
console.log(evenNumbers);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Problem-3
2+
3+
Use a for...of loop to concatenate all the elements of an array into a single string.
4+
5+
Input: let names = ['Tom', 'Tim', 'Tin', 'Tik']
6+
7+
Output: 'TomTimTinTik'
8+
*/
9+
10+
let names = ['Tom', 'Tim', 'Tin', 'Tik'];
11+
12+
// Solution-1
13+
let newArray = '';
14+
for (let name of names) {
15+
newArray += name
16+
}
17+
console.log(newArray);
18+
19+
20+
// Solution-2 (Short)
21+
let addAllName = names.join('');
22+
console.log(addAllName);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Problem-4
2+
3+
Reverse the words of a sentence. Only the position of the word will be reversed. check out the output
4+
5+
Input: const statement = "I am a hard working person"
6+
7+
Output: "I am a hard working person"
8+
*/
9+
const statement = "I am a hard working person";
10+
let reverseStatement = statement.split(" ").reverse().join(" ");
11+
console.log(reverseStatement);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Problem-1
2+
3+
Write a JavaScript code to reverse the array colors without using the reverse method.
4+
5+
Input: const colors = ['red', 'blue', 'green', 'yellow', 'orange']
6+
7+
Output: ['orange', 'yellow', 'green', 'blue', 'red']
8+
*/
9+
10+
const colors = ['red', 'blue', 'green', 'yellow', 'orange'];
11+
12+
// solution-1 by for of loop
13+
const reverseColor = [];
14+
for (const color of colors) {
15+
reverseColor.unshift(color);
16+
}
17+
console.log(reverseColor);
18+
19+
20+
// solution-2 by for loop
21+
22+
const revColor = [];
23+
for (let i = 0; i < colors.length; i++) {
24+
const color = colors[i];
25+
revColor.unshift(color)
26+
}
27+
console.log(revColor);
28+
29+
30+
// solution-3 by for loop (decrements -- )
31+
const decrementColor = [];
32+
for (let i = colors.length - 1; i >= 0; i--) {
33+
const col = colors[i];
34+
decrementColor.push(col)
35+
}
36+
console.log(decrementColor);
37+
38+
39+
// solution-4 Easy method solution Shortcut
40+
41+
colors.reverse();
42+
console.log(colors);

0 commit comments

Comments
 (0)