I added one simple Stack implementation, then the function=palindrome should work as you expected.
And I added one function = palindrome1 which is the simple optimization (only loop for half length of the string) for palindrome judgement.
function Stack()
{
this.stac=new Array();
this.pop=function(){
return this.stac.pop();
};
this.push=function(item){
this.stac.push(item);
};
this.length=function(){
return this.stac.length;
};
}
function palindrome(word){
var s = new Stack();
for (var i=0; i<word.length; i++){
s.push(word[i]);
}
var rword = "";
while (s.length() > 0){
rword+=s.pop();
}
if (word == rword){
return true;
}else{
return false;
}
}
console.log(palindrome('test1'))
console.log(palindrome('manam'))
function palindrome1(word){
var maxIndex = word ? word.length:0;
if(!maxIndex || maxIndex==0) {
return false;
}
var index = 0;
var left = "";
var right = "";
while(index<(maxIndex/2)) {
left += word[index];
right += word[maxIndex-index-1];
index++;
}
return left==right;
}
console.log(palindrome1('test1'))
console.log(palindrome1('manam'))