0

I am looking for a method that compares if 2 arrays have same elements.

Following implementations all return false when order of elements is differnet.

Array(2,1).sameElements(Array(1,2))

Array(1,2).deep == Array(2,1).deep

Array(1,2).corresponds(Array(2,1)){_ == _}

I am currently using it by sorting an array before comparison. But I believe there must be a much more efficient method for implementing this

Array(2,1).sorted.sameElements(Array(1,2).sorted)
res: true
Omley
  • 426
  • 6
  • 17
  • 1
    I am afraid, there is no efficient solution, can you please take a look at this question: http://stackoverflow.com/questions/3622895/is-there-an-api-method-that-compares-contents-of-a-seq-irrespective-of-order I guess this is a duplicate question of that. – Tawkir Mar 09 '17 at 12:31
  • Thanks. That link helped. – Omley Mar 10 '17 at 11:08

0 Answers0