Array#compact Useful JavaScript Game Extension #31

Returns a copy of the array without null and undefined values.
@name compact
@methodOf Array#
@type Array
@returns An array that contains only the non-null values.
Array::compact = -> (element) ->

This array compact method is pretty useful. Prototype.js got it from Ruby and I got it from both. Now it’s a proud member of my CoffeeScript corelib.

Not much interesting behavior wise, but one thing to take note of is how short and sweet the code is thanks to using CoffeeScript.

31 down, 225 to go. Peace!

Leave a Reply

Your email address will not be published. Required fields are marked *