Skip to content

Instantly share code, notes, and snippets.

@searls
Created February 1, 2012 23:33
Show Gist options
  • Save searls/1720156 to your computer and use it in GitHub Desktop.
Save searls/1720156 to your computer and use it in GitHub Desktop.
data =
a: 0
b: "foo"
result = _(data).reject((v,k) -> k == 'b')
expect(result).toEqual(a: 0) #but fail! it returns: [0]
# so far now, I could settle for this:
newData = _(data).clone()
_(newData).each (v,k) -> delete newData[k] if k == 'b'
@searls
Copy link
Author

searls commented Feb 1, 2012

Right, I'm just using _.reject as an example. Most of the collection functions iterate perfectly well over objects, but only return arrays. That always surprises me.

@zspencer
Copy link

zspencer commented Feb 1, 2012

Yea, It does seem odd. I've hacked together a gist that could become a _(data).object_reject: https://gist.github.com/1720187

A better option would be to extend underscore to make it saner when it's iterating over an object.

@searls
Copy link
Author

searls commented Feb 1, 2012

Thanks Zach. Yeah, I just hacked my own underscore mixin _.withoutProperties

http://tryjasmine.com/?gist=1720249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment