Skip to content

Instantly share code, notes, and snippets.

@mnzk
Created September 29, 2011 05:51
Show Gist options
  • Save mnzk/1250074 to your computer and use it in GitHub Desktop.
Save mnzk/1250074 to your computer and use it in GitHub Desktop.
drop-start-same
(defn drop-start-same
[ss]
(->> (loop [ss ss]
(if (apply = (map first ss))
(recur (map rest ss))
ss))
(map (partial apply str))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn drop-start-same
[ss]
(let [chop-len (->> (apply map list ss)
(take-while (partial apply =))
count)
chop (partial drop chop-len)
cs2str (partial apply str)]
(map (comp cs2str chop) ss)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; examples
;;
;; (drop-start-same ["abcdef" "abc123"])
;; ;; => ("def" "123")
;;
;; (drop-start-same ["あいさんさん" "あいどる" "あいうえお" "あいんしゅたいん"])
;; ;; => ("さんさん" "どる" "うえお" "んしゅたいん")
;;
;; (drop-start-same ["12345" "67890" "abc"])
;; ;; => ("12345" "67890" "abc")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment