5 ms·
The element frequency counting example (in the grey box) is pretty ambiguous. Are you just supposed to ignore the numbers and instead count the frequencies of
by herdrick 16y ago
The element frequency counting example (in the grey box) is pretty ambiguous. Are you just supposed to ignore the numbers and instead count the frequencies of the strings? Or is the first element of each sublist to be the addend? I.e. should it be the number added to the total count of string elements?
Either way, Clojure looks pretty good. If the first case, then it's
(frequencies (flatten (map second l)))
If the second interpretation, then this works:
(apply merge-with + (map (comp (partial apply hash-map) reverse) l))