Created
May 8, 2015 17:34
-
-
Save glinesbdev/4a3dd73d03309a3cb388 to your computer and use it in GitHub Desktop.
Palindrome Module
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
// [declare namespace] | |
var FourLife = FourLife || {}; | |
// [declare module] | |
FourLife.PalindromeChallenge = (function() { | |
// [strict mode] | |
'use strict'; | |
// [private variable(s)] | |
var _splitStr = [], | |
_reversedStr = '', | |
_status = false, | |
_regex = /[\W+_]/g; | |
// [private function(s)] | |
var _palindromeCheck = function(string) { | |
try { | |
for (var i = 0; i < string.length; i++) { | |
_splitStr = string.split(''); | |
_reversedStr = _splitStr.reverse().join(''); | |
} | |
_reversedStr = _reversedStr.replace(_regex, '').toLowerCase(); | |
string = string.replace(_regex, '').toLowerCase(); | |
_status = _reversedStr === string ? true : false; | |
_status = _status ? 'Yes' : 'No'; | |
} catch (error) { | |
if (string === undefined || error instanceof TypeError) { | |
_status = 'You must provide a string.'; | |
} | |
} finally { | |
return _status; | |
} | |
}; | |
// [public method(s)] | |
return { | |
isPalindrome: _palindromeCheck | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment