Created
April 12, 2016 17:29
-
-
Save timsgardner/20804daceb27d175fe56d08ccac7e81c to your computer and use it in GitHub Desktop.
vector insert!
This file contains hidden or 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 vector-insert [v1 v2 i] | |
(let [c1 (count v1) | |
c2 (count v2) | |
c3 (+ c1 c2)] | |
(persistent! | |
(loop [j i, v3 (transient v1)] | |
(cond | |
(< j (+ i c2)) | |
(recur | |
(inc j) | |
(assoc! v3 j (get v2 (- j i)))) | |
(< j c3) | |
(recur | |
(inc j) | |
(assoc! v3 j (get v1 (- j c2)))) | |
:else v3))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment