-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript2.js
67 lines (40 loc) · 1.6 KB
/
script2.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// // Print odd numbers in an array
// // Convert all the strings to title caps in a string array
// // Sum of all numbers in an array
// // Return all the prime numbers in an array
// // Return all the palindromes in an array
// //1. Print odd numbers in an array
// let numberArray = [1, 2, 3, 4, 5, 6, 98, 101, 467]
// console.log("Odd Numbers in Number Array are: " + numberArray.filter((item) => {
// return item % 2 !== 0
// }))
// //2.Convert all the strings to title caps in a string array
// let stringArray = ["Madhan", "is", "a", "smart", "developer"]
// stringArray = stringArray.map((item) => {
// return item.toUpperCase()
// })
// console.log("Converted String Array is: " + stringArray)
// //3.Sum of all numbers in an array
// //using numArray Defined Above
// let sum = numberArray.reduce((currentTotal, item) => {
// return currentTotal + item
// }, 0)
// console.log("Sum of elements in Number Array: " + sum)
// //4.Return all the prime numbers in an array
// console.log("Prime Number is Array are: " +
// numberArray.filter((item) => {
// for (let i = 2; i < item; i++) {
// if (item % i === 0)
// return false;
// }
// return item !== 1;
// }))
// //5.Return all the palindromes in an array
// let arrayPallindrome = [111, 102, 505, 323, 612, 776, 707, 121]
// console.log("Pallindrome Numbers in array are: " +
// arrayPallindrome.filter((item) => {
// let temp = item + "";
// if (temp.split('').reverse().join('') === item + "")
// return true
// return false
// }))