coffeescript-cookbook/coffeescript-cookbook.github.com — pull request #107 by pkinsky (2014-04-23 19:55:43+00:00)
Title: Correct unique for empty arrays

As defined here: http://coffeescriptcookbook.com/chapters/arrays/removing-duplicate-elements-from-arrays

```
Array::unique = ->
output = {}
output[@[key]] = @[key] for key in [0...@length]
value for key, value of output
```

[].unique() evaluates to [null] in the latest version of Chrome.

This can be fixed by using the 'own' keyword to only iterate over output's own properties.

```
Array::unique = ->
output = {}
output[@[key]] = @[key] for key in [0...@length]
value for own key, value of output
```
[].unique() evaluates to [] in the latest version of Chrome.

I'm not sure why null is a property of the empty array, but javascript can be weird like that.

An alternative fix would be to just return an empty array if @length == 0