Skip to content

Instantly share code, notes, and snippets.

@jprudent
Last active December 21, 2015 22:29
Show Gist options
  • Save jprudent/6375265 to your computer and use it in GitHub Desktop.
Save jprudent/6375265 to your computer and use it in GitHub Desktop.
substract 2 vectors in clojure
(defn minus [v1 v2]
"substract 2 vectors, v2 must be a subset of v1"
(reduce (fn [acc v]
(let [index (.indexOf acc v)]
(into (subvec acc 0 index) (subvec acc (inc index))))) v1 v2))
(minus [:c :a :b :b :a :a :b] [:a :a :b :a]) ; [:c :b :b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment