Unique recipe fails on empty arrays
inanna-malick opened this issue · 2 comments
inanna-malick commented
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.
michaelglass commented
you wanna PR this change?
inanna-malick commented
Sorry, I'll do that.
PS: thanks for the great resource