Created
March 31, 2013 22:06
-
-
Save notslang/5282186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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