Skip to content

Instantly share code, notes, and snippets.

@turgay
Last active July 15, 2020 03:11
Show Gist options
  • Select an option

  • Save turgay/2d29c0e906922ccfcd93 to your computer and use it in GitHub Desktop.

Select an option

Save turgay/2d29c0e906922ccfcd93 to your computer and use it in GitHub Desktop.
Find duplicates in a sequence using Clojure
(defn extract-names [seq]
(for [lib seq :let [dot-index (.indexOf lib ".")]]
(subs lib 0 (- dot-index 2))))
;(println (extract-names ["x-security-1.0.7.jar" "aksis-1.0.jar" "antlr-2.7.6.jar"]))
(defn dups [seq]
(for [[id freq] (frequencies seq) ;; get the frequencies, destructure
:when (> freq 1)] ;; this is the filter condition
id))
(println (dups (extract-names [
"asm-3.2.jar"
"asm-analysis-3.2.jar"
"asm-commons-3.2.jar"
"asm-tree-3.2.jar"
"asm-util-3.2.jar"
"castor-1.2.jar"
"cglib-2.2.jar"
"cglib-nodep-2.1_3.jar"
"commons-pool-1.3.jar"
"docx4j-3.0.1.jar"
"dom4j-1.6.1.jar"
"jsoup-1.7.2.jar"
"jsoup-1.7.3.jar"
"ognl-2.6.11.jar"
"ognl-2.6.9.jar"
"sac-1.4.jar"
])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment