Groovy web console

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

palindrome-wannabe

Published 1 month ago by totoro
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def test = ['kajak':true, 'kakaj':true, '': false, 'a':true, 'foo': true, 'foobar':false]

test.each{
    if(!check(it.key) == it.value){
        println "invalid result for ${it.key}"
    }
}

def check(s){
    if (!s){
        return false
    }
    return s.inject([] as Set){ result, it ->
        if (result.contains(it)){
            result.remove(it)
        } else {
            result.add(it)
        }
        return result
    }.size() < 2
}