This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BubbleSort { | |
def list | |
def sort() { | |
def eachPairIndex = { Collection l -> | |
def range = 0..<l.size() | |
[range, range.tail()].transpose() | |
} | |
while (! eachPairIndex(this.list).inject(true) { rslt, idx -> | |
if (! (this.list[idx[0]] < this.list[idx[1]]) ) { | |
use(Collections){ this.list.swap(idx[0], idx[1]) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def origin = 'あいうえお' | |
def encoded = '%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A' | |
assert URLEncoder.encode(origin, 'UTF-8') == encoded | |
assert URLDecoder.decode(encoded, 'UTF-8') == origin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'abcdef'.each { | |
println it | |
} | |
for (s in '123456') { | |
println s | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert 100 == Math.abs(100) | |
assert 100 == Math.abs(-100) | |
assert 0 == Math.abs(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert 'foobar' == 'foo' + 'bar' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. String#substringを使う。 | |
assert '0123456'.substring(2, 4) == '23' | |
// 2. Object#getAtで範囲を使う。 (GDK) | |
assert '0123456'[2..3] == '23' | |
assert '0123456'[2..<4] == '23' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert 'HI, GROOVYIST' == 'Hi, Groovyist'.toUpperCase() | |
assert 'hi, groovyist' == 'Hi, Groovyist'.toLowerCase() |