-
Notifications
You must be signed in to change notification settings - Fork 0
/
palindrome.js
63 lines (37 loc) · 1.1 KB
/
palindrome.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
// using IIFE AND ANNONYMOUS FUNCTION
var array = [101, 121, 151, 100, 52, 102, 91519, 235, 232, 959];
(function (array) {
var div = 0;
var store = array.filter((number) => {
var temp = number;
var sum = 0;
while (temp != 0) {
div = temp % 10;
sum = sum * 10 + div;
temp = parseInt(temp / 10);
}
if (sum == number)
return true;
})
console.log(store);
})(array);
//output- [101, 121, 151, 91519, 232, 959]
//below- using arrow function
var array1 = [101, 121, 151, 100, 52, 102, 91519, 235, 232, 959];
var palindrome = (array1) => {
var div = 0;
var store = array1.filter((number) => {
var temp = number;
var sum = 0;
while (temp != 0) {
div = temp % 10;
sum = sum * 10 + div;
temp = parseInt(temp / 10);
}
if (sum == number)
return true;
})
console.log(store);
}
palindrome(array1);
//output- [101, 121, 151, 91519, 232, 959]