Skip to main content
Notice removed Needs detailed answers by rolfl
Move comment to post
Source Link
rolfl
  • 97.5k
  • 17
  • 218
  • 418

Here's a one liner similar to Flambinos:, but in my version, rather than mapping, producing unwanted nils, then compacting them, you are simply selecting the elements that you want. The intent is more transparent. It also allows you to use blocks with one argument only. These are subtle benefits, to be sure, and I like Flambino's solution, but I thought the improvement was worth posting

(people1 + people2).group_by {|x| x[:name]}.values.select {|x| x.size > 1}

Here's a one liner similar to Flambinos:

(people1 + people2).group_by {|x| x[:name]}.values.select {|x| x.size > 1}

Here's a one liner similar to Flambinos, but in my version, rather than mapping, producing unwanted nils, then compacting them, you are simply selecting the elements that you want. The intent is more transparent. It also allows you to use blocks with one argument only. These are subtle benefits, to be sure, and I like Flambino's solution, but I thought the improvement was worth posting

(people1 + people2).group_by {|x| x[:name]}.values.select {|x| x.size > 1}
Notice added Needs detailed answers by Jamal
Source Link
Jonah
  • 4.4k
  • 14
  • 22

Here's a one liner similar to Flambinos:

(people1 + people2).group_by {|x| x[:name]}.values.select {|x| x.size > 1}