1

If I have sequence

[1 1 1 1 3 2 4 1]

how can I remove a particular number from that sequence? For example

(remove [1 1 1 1 3 2 4 1] 1) -> [3 2 4]

1 Answer 1

4

You can use a set as a predicate to remove, because sets can be called as functions.

(remove #{1} [1 1 1 1 3 2 4 1])
=> (3 2 4)

wrap that in (vec ..) if you need the result to be a vector.

The bonus of that approach is that you could remove many arbitrary values by sticking them in the set. If it's just one, this of course works too:

(remove #(= 1 %) [1 1 1 1 3 2 4 1])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.