Closed askucher closed 6 years ago
I think this is easy enough:
o = [{ x: 1, y: 2}, { x: 2 }, { x: 2, y: 3}]
o |> filter (.x == 1)
o |> filter (.x == 2 && it.y == 3)
How to do it yourself if you want that API anyway:
compare = (template, actual) -->
(for let key, value of template
actual[key] is value)
.every (is true)
o = [{ x: 1, y: 2}, { x: 2 }, { x: 2, y: 3}]
o.filter compare { x: 1 }
|> console.log # => [ { x: 1, y: 2 } ]
@gkz sometimes better build a condition as object. for instance for filtering
the table
filter
works fine withfunctions
but sometimes better to filter byobject
expected
=> [{ x: 1, y: 2}]
actualthrown n is not a function