Paul
Paul

Reputation: 75

Clojure - Indexing elements of an Array

I have an array of elements that has been divided up into groups although I need to make reference to each grouping specifically using a letter for each. So far I have sorted and split the array but I am unsure of what the next step would be or if there is a more intuitive way to process this, my steps so far are below:

data(map(keyword :counter)querieddata)
sortedlist(sort > tosort)
part(into [] (partition-all (/ (count data) 10) sortedlist))

Ideally I'd like my output to be something like:

[(:a 40 40 36 33) (:b 33 30 27 25) (:c 25 19 18 5)]

Any help is greatly appreciated!

Upvotes: 1

Views: 351

Answers (1)

guilespi
guilespi

Reputation: 4702

Use zipmap

 user=> (zipmap [:a :b :c :d :e] [1 2 3 4 5])
 {:e 5, :d 4, :c 3, :b 2, :a 1}

In your particular case the second list is the grouped results

 user=> (zipmap [:a :b :c :d :e] [[1 2 3] [4 5 6] [7 8 9]])
 {:c [7 8 9], :b [4 5 6], :a [1 2 3]}

Upvotes: 3

Related Questions