18 lines
364 B
Plaintext
18 lines
364 B
Plaintext
/* Palindrome detection, in Jsish */
|
|
function isPalindrome(str:string, exact:boolean=true) {
|
|
if (!exact) {
|
|
str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
}
|
|
return str === str.split('').reverse().join('');
|
|
}
|
|
|
|
;isPalindrome('BUB');
|
|
;isPalindrome('CUB');
|
|
|
|
/*
|
|
=!EXPECTSTART!=
|
|
isPalindrome('BUB') ==> true
|
|
isPalindrome('CUB') ==> false
|
|
=!EXPECTEND!=
|
|
*/
|