Groovy web console

subscribe to the feed Subscribe
to this
site
groupBy (via #groovywebconsole)
tweet this snippet Tweet
this
script

groupBy

Published 2 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def data = [     
[rating: 4, count: 100],     
[rating: 4, count: 300],     
[rating: 5, count: 100],     
]  
data.groupBy { it.rating }.collect { k,v -> 
    [rating: k, count: v.count.sum()]
}