Skip to content

Instantly share code, notes, and snippets.

@emanon001
Last active December 18, 2015 07:09
Show Gist options
  • Save emanon001/5744186 to your computer and use it in GitHub Desktop.
Save emanon001/5744186 to your computer and use it in GitHub Desktop.
;;;; 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