Skip to content

Commit e3e5bd5

Browse files
committed
largest no and pallindrome string program added
1 parent 77a49d9 commit e3e5bd5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

largestNumber.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let num = [2, 8, 3, 6, 89, 23, 56, 28];
2+
3+
const find_largest_no = (num) => {
4+
let largest_no = num[0];
5+
6+
for (let i = 0; i <= num.length - 1; i++) {
7+
if (num[i] > largest_no) {
8+
largest_no = num[i];
9+
}
10+
}
11+
return largest_no;
12+
};
13+
14+
const res_largest_no = find_largest_no(num);
15+
console.log(res_largest_no);

pallindromeString.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
let str = "hayah";
2+
let isPallindrome = true;
3+
4+
const checkPalindrome = (str) => {
5+
let str_split = str.split("");
6+
7+
for (
8+
let i = 0, j = str_split.length - 1;
9+
i <= (str_split.length - 1) / 2, j >= (str_split.length - 1) / 2;
10+
i++, j--
11+
) {
12+
if (str_split[i] !== str_split[j]) {
13+
isPallindrome = false;
14+
break;
15+
}
16+
}
17+
if (isPallindrome) {
18+
console.log(str + " is a pallindrome");
19+
} else {
20+
console.log(str + " is not a pallindrome");
21+
}
22+
};
23+
24+
checkPalindrome(str);

0 commit comments

Comments
 (0)