Created
August 12, 2011 13:56
-
-
Save irof/1142079 to your computer and use it in GitHub Desktop.
お題:文字列を先頭から見て同じところまで除去
This file contains 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 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