1

I am trying to compare different orderd List of Immutable js. I thought "equals" would be work, but it is only true when is same order.

is there any way to compare for containing same content?

var list1 = Immutable.List.of({a:1},2,{b:3},4);
var list2 = Immutable.List.of(2,{a:1},4,{b:3});
console.log(list1.equals(list2)) //false
Elin Jung
  • 15
  • 3

1 Answers1

0

There are two problems:

  1. by definition, order is essential to lists
  2. Two ordinary Javascript objects are never equal to each other, even if they have the same contents.

You could, however, do this:

const set1 = Immutable.Set.of(Immutable.Map({a:1}),2,Immutable.Map({b:3}),4);
const set2 = Immutable.Set.of(2,Immutable.Map({a:1}),4,Immutable.Map({b:3}));
console.log(set1.equals(set2)) //true

Nota bene: using var with an immutable defeats the entire purpose! . Use const.

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144