Skip to content

Instantly share code, notes, and snippets.

@kunal-mandalia
Created January 6, 2018 11:47
Show Gist options
  • Save kunal-mandalia/d3859f17fb09b8ad8d63a490a46cd97c to your computer and use it in GitHub Desktop.
Save kunal-mandalia/d3859f17fb09b8ad8d63a490a46cd97c to your computer and use it in GitHub Desktop.
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