Skip to content

Commit 0d7bb13

Browse files
committed
some array methods are used in this programs
1 parent 7f614cc commit 0d7bb13

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

check_anagrams.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function areAnagrams(str1, str2) {
2+
if (str1.length !== str2.length) {
3+
return false;
4+
}
5+
let count = {};
6+
7+
for (let i = 0; i < str1.length; i++) {
8+
count[str1[i]] = (count[str1[i]] || 0) + 1;
9+
}
10+
11+
for (let i = 0; i < str2.length; i++) {
12+
if (!count[str2[i]]) {
13+
return false;
14+
}
15+
count[str2[i]]--;
16+
}
17+
18+
return true;
19+
}
20+
21+
console.log(areAnagrams("listen", "silent"));
22+
console.log(areAnagrams("hello", "world"));

factorial.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const number = 5;
2+
3+
const find_factorial = (num) => {
4+
let fact = 1;
5+
for (let i = num; i >= 1; i--) {
6+
fact = fact * i;
7+
}
8+
return fact;
9+
};
10+
11+
const res = find_factorial(number);
12+
console.log(res);

summ_array_elements.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const arr = [8, 9, 5, 6, 4, 6, 2, 3, 7];
2+
3+
const sum = arr.reduce((total, current) => total + current, 0);
4+
console.log(sum);

0 commit comments

Comments
 (0)