-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductPalindrome.js
47 lines (42 loc) · 989 Bytes
/
productPalindrome.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
const isPalindrome = function(product) {
let count = 0;
let message = "No";
let limit = Math.floor(product.length/2);
for(attempt = 0; attempt < limit ; attempt++){
if(product[attempt] == product[(product.length-1)-attempt]) {
count++;
}
}
if(count == limit){
message = "Yes";
}
return message;
}
const findPair = function(number) {
let number2 = number;
product = checkPalindrome(number,number2);
return product;
}
const checkPalindrome = function(number,number2) {
let product;
let message;
let start = number2;
for(number; number > 0; number--) {
number2 = start;
while(number2 >= number) {
product = ""+(number2*number);
console.log(product);
message = isPalindrome(product);
if(message == "Yes") {
return product;
}
number2--;
}
}
}
const main = function() {
let number = process.argv[2];
palindromePair = findPair(number);
console.log(palindromePair);
}
main();