Created
January 6, 2018 11:47
-
-
Save kunal-mandalia/d3859f17fb09b8ad8d63a490a46cd97c 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
const assert = require('assert') | |
function isPalindrome (arg) { | |
if (typeof arg !== 'string') return false; | |
const alphanumericOnly = arg.replace(/[^a-z0-9]/gi, ""); | |
return alphanumericOnly === alphanumericOnly.split('').reverse().join(''); | |
} | |
function runTests () { | |
const cases = [ | |
{input: null, output: false}, | |
{input: 123, output: false}, | |
{input: 'abc', output: false}, | |
{input: 'pollop', output: true}, | |
{input: 'poll£op@', output: true} | |
]; | |
cases.forEach((c, i) => { | |
const result = isPalindrome(c.input); | |
assert(result === c.output, `Test case ${i} failed: ${c.input}`); | |
}) | |
} | |
runTests(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment