Skip to content

Instantly share code, notes, and snippets.

@visibletrap
Last active May 3, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visibletrap/3ce4cc7d033153b0724558a714922082 to your computer and use it in GitHub Desktop.
Save visibletrap/3ce4cc7d033153b0724558a714922082 to your computer and use it in GitHub Desktop.
Given input: {1 [:a :b], 2 [:a], 3 [:b], 4 [:b :c], 5 [:a], 6 [:a :c :e]}. Expected output: {:a [1 2 5 6], :b [1 3 4], :c [4 6], :e [6]}
(->> {1 [:a :b], 2 [:a], 3 [:b], 4 [:b :c], 5 [:a], 6 [:a :c :e]}
(map (fn [[k v]] (zipmap v (repeat [k]))))
(apply merge-with into))
;=> {:a [1 2 5 6], :b [1 3 4], :c [4 6], :e [6]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment