I have this list:
("a" "b" "c" "d" "e")
I want to move "d" in the first position:
("d" "a" "b" "c" "e")
Is there any straightforward way to do this?
EDIT
Thanks for the answers. I had a look into it and I did this:
(defn move-item [data item-to-move]
(conj (remove #(= % item-to-move) data) item-to-move))
(move-item ["a" "b" "c" "d" "e"] ["d"])
I am not sure if this is good design, but it does the trick.
functions that can be helpful:
1. rotate
user=> (defn rotate [xs] (cons (last xs) (drop-last xs)))
#'user/rotate
user=> (rotate '(1 2 3))
(3 1 2)
2. replace
user=> (replace {1 4} [1 2 3 4])
[4 2 3 4]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With