Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js equivalent of .difference?

Does Ember have a .difference function like underscore does? I have an ArrayController with a set of objects in each one. I want to subtract all the objects in ArrayController2 from ArrayController1 :

ArrayController1:
   1
   2
   3
   4

ArrayController2:
   2
   4

Then do the difference:

ArrayController1.difference(ArrayController2) => 1
                                                 3
like image 874
rickyduck Avatar asked Jan 25 '13 14:01

rickyduck


1 Answers

I don't think there is an single method that will do that, but you could write a helper that essentially did the following:

array1.reject((function(item) {
  return array2.contains(item);
}), array2);

Just looping through array1 and rejecting anything that returns true for array2.contains().

like image 54
Andre Malan Avatar answered Oct 06 '22 13:10

Andre Malan