The code below is for checking whether the input string is palindrome or not
const { argv } = require("process");
(()=>{
var palindrom01 = palindrom01;
palindrom01();
function palindrom01(){
let inputNum = argv[2];
let totalLength = inputNum.length;
let half_length = parseInt(totalLength/2);
let flag = true;
for(let i = 0, j = (totalLength - 1); i < half_length; i++){
if(inputNum.charAt(i) !== inputNum.charAt(j)){
flag = false;
break;
}
j--;
}
console.log(`input ${inputNum} is Palinform => ${flag}`);
}
})();
This is the output of the code
D:\> node .\palindrom.js 12321
input 12321 is Palinform => true
D:\> node .\palindrom.js 123321
input 123321 is Palinform => true
D:\> node .\palindrom.js 12345
input 12345 is Palinform => false
D:\>
Is Panlindrome properly implemented? if yes, is there a way better way to do it ?