Groovy web console

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

awesome

Published 10 months ago by totoro
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def s = "abcfjfoobarkooooxxpzz"

println s.inject([]){ res, it ->
    if (!res.empty && !res.last().empty && res.last()[0] == it){
        res.last().push(it);
    } else {
        res.push([it])
    }
    res
}.collect{
    it.size() / 2 as int
}.sum()