Skip to content

Instantly share code, notes, and snippets.

@eneroth
Last active February 27, 2019 18:32
Show Gist options
  • Save eneroth/745c65385ee21eedc6322ea741d259da to your computer and use it in GitHub Desktop.
Save eneroth/745c65385ee21eedc6322ea741d259da to your computer and use it in GitHub Desktop.
Flips attributes around
(defn flip-attrs [attributes]
(let [one (clojure.string/split attributes #"&")
two (map #(clojure.string/split % #"=") one)
three (map reverse two)
four (map #(interpose "=" %) three)
five (interpose "&" four)
six (flatten five)]
(apply str six)))
(flip-attrs "tool=whip&clothing=hat&sidearm=pistol")
;; => "whip=tool&hat=clothing&pistol=sidearm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment