r/programming • • Aug 10 '12

Write any javascript code with just these characters: ()[]{}+!

http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html
1.3k Upvotes

288 comments sorted by

View all comments

Show parent comments

14

u/[deleted] Aug 10 '12

To represent 12 in decimal you do "1"+"2"

+((+!![]+[])+(!+[]+!![]))

but with powers of two it will be 4+8

!+[]+!![]+!![]+!![]+!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]

2

u/[deleted] Aug 10 '12

It took me a min to figure out how he had written 12 in the article but it is an elegant solution.