Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You have some nice functional stuff. You can define a function on a primitive type like an integer. This enables you to have code like 400.times(doX). doX is a function. Functions as first class citizens are nice.

If you have a function as a final argument, you can change this: something(a, b, { }) to something(a, b) { }. Basically, you just put your anonymous function on the outside of the parenthesis.

I think the book's example was something along the lines of sort(arr) { $1 > $2 }. I think that $1 is some kind of default specifier for the first param and $2 for the second, but I'm not sure.



You're correct about the $1 syntax representing parameters, but the parameter indices start at 0: sort(arr) { $0 > $1 }




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: