All that’s great about CoffeeScript in 40 characters
blog.mackerron.com
blog.mackerron.com
Array::compact = -> x for x in @ when x?
In es6: Array.prototype.compact = function() {
return this.filter(x => x !== null);
}
I find it easier to read than OP's example, but I would like to see non-lexically bound this function shorthand in es6/7. I see a mention of it at the bottom of this spec[1], but not sure what they mean by "Initializer opt". Maybe like this: Array.prototype.compact = this => this.filter(x => x !== null)
[1] http://tc39wiki.calculist.org/es6/arrow-functions/[].filter(function(item) { return item != null; });
It's not patched on the prototype, but I'm not sure why something that simple needs to be.
Now let's move on to the truly relevant and constructive activity: comparing which language has best-looking toy quicksort implementation