set-component

Set container

set

Generic Set container

$ component install component/set
var Set = require('set');
var set = new Set;
 
set.add('foo');
set.add('foo');
set.add({ some: 'object' });
set.remove('foo');
 
set.values();
// => [{ some: 'object' }] 

Set supports an .equals(other) method when present, for example you may then add two separate User instances that are identified as being the same via their name:

User.prototype.equals = function(user){
  return this.name == user.name;
};

Create a new Set.

Create a new Set with values array. Duplicates will be removed.

Add value to the set.

Remove value from the set, returning true when present, otherwise returning false.

Check if value is present.

Return an array of values.

Aliased as .toJSON().

Iterate each member and invoke fn(val).

Return the set size.

Empty the set and return the old values array.

Check if the set is empty.

Perform a union with set and return a new Set.

Perform an intersection with set and return a new Set.

MIT