except(second[, comparer, arg])

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.

Examples

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

var onlyInFirstSet = $from(numbers1).except(numbers2);

onlyInFirstSet.each("document.writeln($)");

/*
 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)";

var except =
    $from(fruits1).except(fruits2, comparer);

except.each("document.writeln($name + ' '+ $code)");

/*
  This code produces the following output:

  orange 4
  lemon 12
*/

Last edited May 16, 2012 at 6:29 AM by suckgamoni, version 1

Comments

No comments yet.