4 ms·
You actually want ".reduce(:|)", & does intersection on arrays. You can replace that .tap block with gsub abuse for a bit more golfing, and can replace the map/
by awj 14y ago
You actually want ".reduce(:|)", & does intersection on arrays. You can replace that .tap block with gsub abuse for a bit more golfing, and can replace the map/reduce combo with flat_map/uniq to eliminate one symbol-to-proc:
def sorted_key_list(maps)
maps.flat_map(&:keys)
.uniq
.sort
.join(",").gsub /^$/, "<none>"
end
- petercooper 14y agoD'oh, I misread the spec; this is where understanding the Clojure properly may have helped too. I thought the keys had to be in both maps, not the keys from both maps. Good call on the | and flat_map then :-)