I have the challenge of writing a code to check if a text is a palindrome or not. I have not finished the code at the moment, it's like this:
function checkPalindrome(str) {
var direita = [];
for(var i = 0; i<str.length; i++){
direita.unshift(str.charAt(i));
}
console.log(direita);
var esquerda = [];
for (var j=str.length-1; j>=0; j--){
esquerda.push(str.charAt(j));
}
console.log(esquerda);
};
So far I wanted to see if I could read a string normally and the other way around. It would play the two readings in 1 vector each for later, compare them and say if it is palindrome or not. Anyway, it happens that when we test in the Google Chrome console or another, it executes only esquerda.push(str.charAt(j));
for the two vectors, not reading the necessary two-way expression. What could be wrong?
A palindrome is a text that can be read normally, or inverted, which will have the same meaning. Example: "revive", "blue light", "radar".