Skip to content

except(second[, comparer, arg])

suckgamoni edited this page May 14, 2013 · 1 revision

Produces the set difference of two sequences by using the specified equality comparer to compare values.

Syntax

Parameters

second

An iteratable object whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

comparer

Type: function(value, key, arg): boolean
An equality comparer to compare values.

arg

An external argument.

Return Value

A sequence that contains the set difference of the elements of two sequences.


Example

var numbers1 = [ 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 ];
var numbers2 = [ 2.2 ];

from(numbers1)
    .except(numbers2)
    .each('console.log($)');

/*
 This code produces the following output:

 2
 2.1
 2.3
 2.4
 2.5
*/
var fruits1 = [ { name: "apple", code: 9 }, 
                { name: "orange", code: 4 },
                { name: "lemon", code: 12 } ];

var fruits2 = [ { name: "apple", code: 9 } ];

//Get all the elements from the first array
//except for the elements from the second array.

var comparer = "#0 == #1 || (#0 && #1 && #0.name == #1.name && #0.code == #1.code)";

from(fruits1)
    .except(fruits2, comparer);
    .each("console.log($name + ' '+ $code)");

/*
  This code produces the following output:

  orange 4
  lemon 12
*/
Clone this wiki locally