Last active
December 18, 2015 07:09
-
-
Save emanon001/5744186 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
;;;; http://npnl.hatenablog.jp/entry/20110812/1313138407 | |
(ns twenty-five-minutes-programming.drop-starts-same | |
(:use [clojure.test :only [are]])) | |
(defn drop-starts-same | |
[& args] | |
(if (some empty? args) | |
args | |
(let [drop-count | |
(->> args | |
(apply map vector) | |
(take-while (partial apply =)) | |
count)] | |
(->> args | |
(map (partial drop drop-count)) | |
(map (partial apply str)))))) | |
(are [args expected] | |
(= (apply drop-starts-same args) expected) | |
["abcdef" "abc123"] ["def" "123"] | |
["あいうえお" "あいさんさん" "あいどる"] ["うえお" "さんさん" "どる"] | |
["12345" "67890" "12abc"] ["12345" "67890" "12abc"] | |
["a" "ab" "abc"] ["" "b" "bc"] | |
[nil "a" "ab"] [nil "a" "ab"] | |
["" "a" "ab"] ["" "a" "ab"] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment