This works, but it still looks dirty, mostly due to javascript's lack of concise lambda-syntax.<p>If you want to use a functional language, it would seem more fitting to create an actual functional language with actual list comprehension, something javascript is ridiculously weak at, and so on.<p>Ofcourse that would then have to be compiled into something which runs in the browser. Another argument for web-bytecode I guess.<p>Edit: To not just throw hot air around, I tried doing something similar (with typing on top!) during a weekend long long ago. I wasn't happy about the result, but I left the code online.<p>For those curious about my take on the same problem: <a href="http://code.kjonigsen.net/js/spicejs/test.html" rel="nofollow">http://code.kjonigsen.net/js/spicejs/test.html</a><p>You'll have to view the source to see how it works, and open the web-developer console to see the output.