0

Say I have the following table:

[
  {numberOfRedStripes: 7, numberOfBlueStripes: 6, stars: 50, foo: "bar"},
  {numberOfRedStripes: 1, numberOfBlueStripes: 1, stars: 0, something: "else"}
]

How can I use regex in order to pluck only the docs which their KEYS start with the string 'numberOf', so that the result would be:

 [
      {numberOfRedStripes: 7, numberOfBlueStripes: 6},
      {numberOfRedStripes: 1, numberOfBlueStripes: 1}
 ]

?

jww
  • 97,681
  • 90
  • 411
  • 885
Kludge
  • 2,653
  • 4
  • 20
  • 42

1 Answers1

0

Does this work?

table.map {|row|
  row.pluck(r.args(row.keys().filter{|key| key.match("^numberOf")}))
}
mlucy
  • 5,249
  • 1
  • 17
  • 21
  • It works, yet in js for example it looks way less readable: table.map(function(row) {return row.pluck(r.args(row.keys().filter(function(key) {return key.match("^numberOf")})))}) – Kludge Oct 13 '14 at 08:38