6
I have the challenge of writing a code to check if a text is a palindrome or not. I haven’t 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 one string normally and the other way around. It would play the two readings in 1 vector each for later, compare them and tell whether it’s palindromic or not.Anyway, it turns out that when we test it on the Google Chrome console or another, it runs only esquerda.push(str.charAt(j));
for the two vectors, not reading the expression in the two necessary directions. What may be wrong?
A palindrome is a text that can be read normally, or reversed, which will have the same meaning. Example: "revive", "blue light", "radar".
It solved my problem and I also learned more. In fact, I also didn’t think whether I should consider sentences or not. At Code Signal it wasn’t clear to me either. Thank you! @Maniero
– Antonio Junior