Skip to content

Instantly share code, notes, and snippets.

@notslang
Created March 31, 2013 22:06
Show Gist options
  • Save notslang/5282186 to your computer and use it in GitHub Desktop.
Save notslang/5282186 to your computer and use it in GitHub Desktop.
function isPalindrome(inputWord){
//split up string
var array = [];
for(i = 0; i < inputWord.length; i++){
array.push(inputWord.charAt(i));
}
if(array.compare(array.clone().reverse())){
return true;
} else {
return false;
}
}
Object.prototype.clone = function() {
var newObj = (this instanceof Array) ? [] : {};
for(var i in this){
if (i == 'clone') continue;
if (this[i] && typeof this[i] == "object") {
newObj[i] = this[i].clone();
} else newObj[i] = this[i];
} return newObj;
};
Array.prototype.compare = function(testArr) {
if (this.length != testArr.length) return false;
for (var i = 0; i < testArr.length; i++) {
if (this[i].compare) {
if (!this[i].compare(testArr[i])) return false;
}
if (this[i] !== testArr[i]) return false;
}
return true;
};
console.log(isPalindrome('bob'));
console.log(isPalindrome('boba'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment