Last active
December 21, 2015 22:29
-
-
Save jprudent/6375265 to your computer and use it in GitHub Desktop.
substract 2 vectors in clojure
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
(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