Created
July 10, 2013 01:58
-
-
Save Sam-Serpoosh/5962892 to your computer and use it in GitHub Desktop.
Cool way of swapping pairs in a collection 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 swap-pairs [items] | |
(into (empty items) | |
(interleave (take-nth 2 (drop 1 items)) | |
(take-nth 2 items)))) | |
(swap-pairs [1 2 3 4 5 6]) ;=> [2 1 4 3 6 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment