Natsu
Natsu

Reputation: 91

Equality of vectors in clojure

I was trying to solve this problem

and I realized that this statement gave output as false.

(= (#(into [] (distinct %)) [1 2 3]) 
   '(1 1 2 2 3 3))

It is supposed to be true as the function is also returning the same vector.

Can someone please explain to me why this is false?

Upvotes: 0

Views: 123

Answers (2)

Thumbnail
Thumbnail

Reputation: 13473

The question you ask is irrelevant to the problem you refer to, which your own answer solves. Looking at the question alone ...

  • As rascio comments, you are applying distinct to the wrong sequence.
  • Furthermore, you can apply = to any two sequences. You don't have to convert the lazy sequence that distinct produces to a vector.

Thus the following suffices ...

(= [1 2 3] (distinct '(1 1 2 2 3 3)))
=> true

Upvotes: 1

Natsu
Natsu

Reputation: 91

From the comments, I found out that I was using the distinct method incorrectly and hence decided to use the repeat method to get the answer which was:

mapcat #(repeat 2 %)

Upvotes: 0

Related Questions