-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn-array-methods.js
More file actions
41 lines (38 loc) · 1.05 KB
/
learn-array-methods.js
File metadata and controls
41 lines (38 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* let arr = ["India", "Srilanka"];
console.log(arr);
arr.push("Australia"); // adds element to the tail
console.log(arr);
arr.pop(); // removes element from the tail
console.log(arr);
arr.unshift("Zimbombay"); // adds element to the head
console.log(arr);
arr.shift(); // removes element from the head
console.log(arr); */
/* let arr = ["a", "z", "e", "b", "h"];
console.log(arr);
console.log(arr.sort()); // rearrange elements in order
console.log(arr.sort().reverse()); // rearrange elements in reverse order
console.log(arr.join("")); // combines elements */
//sum of 7 by adding index
let arr = [1, 2, 3, 4, 5, 6];
let final = 7;
console.log(arr);
let temp = [];
for (let i = 0; i < arr.length; i++) {
for (let j = 1; j < arr.length; j++) {
if (arr[i] + arr[j] === 7) {
temp.push([i, j]);
}
}
}
console.log(temp);
//palindrome
/* let str = "madam";
console.log("Original:", str);
let str1 = str.split("").reverse().join("");
console.log("Reversed:", str1);
if (str === str1) {
console.log("Palindrome");
} else {
console.log("Not palindrome");
} */