Groovy web console

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

palindrome-wannabe

Published 7 months 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){
    return s && s.inject([] as Set){ result, it ->
        it in result ? result - it : result + it
    }.size() < 2
}