Skip to content

Instantly share code, notes, and snippets.

@irof

irof/gist:1142079

Created Aug 12, 2011
Embed
What would you like to do?
お題:文字列を先頭から見て同じところまで除去
def hoge(String... args) {
def i = -1, v = ''
while(++i < args*.size().min() && args.every{it[i] == args[0][i]}) {
v += args[0][i]
}
args*.minus(v)
}
assert hoge('123', '123') == ['','']
assert hoge('112233', '123123') == ['12233', '23123']
assert hoge('なまむぎ', 'なまごめ', 'なまたまご') == ['むぎ', 'ごめ', 'たまご']
assert hoge('abcde', 'abcdefg') == ['', 'fg']
assert hoge('abcdefg', 'abcde') == ['fg', ''] // 追加したテスト
// お題
assert hoge('abcdef', 'abc123') == ['def', '123']
assert hoge("あいうえお", "あいさんさん", "あいどる") == ["うえお", "さんさん", "どる"]
assert hoge("12345", "67890", "12abc") == ["12345", "67890", "12abc" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.