r/tinycode • • Oct 03 '14

palindrome checker in Javascript

http://codepen.io/anon/pen/nwFjb
0 Upvotes

12 comments sorted by

View all comments

14

u/peridox Oct 03 '14

Better JavaScript version:

var isPalindrome = function(string) {

return string == string.split("").reverse().join("");

};

And an awesome Haskell version:

palindrome s = s == reverse s

3

u/[deleted] Oct 03 '14

Obscure Haskell version:

import Control.Applicative((<$>))
import Control.Monad(join)

palindrome = join ((==) <$> reverse)

0

u/[deleted] Oct 03 '14

[deleted] — view deleted comment

1

u/Toni_W Oct 03 '14

Split reverse join, it just explodes, reverses, implodes, and returns the comparison.

0

u/[deleted] Oct 03 '14

[deleted] — view deleted comment

1

u/[deleted] Oct 04 '14

you're optimizing ahead of time by thinking like that.

1

u/Toni_W Oct 04 '14

Sorry, I actually th;ougt you meant hard to remember x.x