Skip to content

Repository files navigation

set

Generic Set container

Installation

$ component install component/set

Example

varSet=require('set');varset=newSet;set.add('foo');set.add('foo');set.add({some: 'object'});set.remove('foo');set.values();// => [{ some: 'object' }]

Equality

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){returnthis.name==user.name;};

API

Set()

Create a new Set.

Set(values)

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

Set#add(value)

Add value to the set.

Set#remove(value)

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

Set#has(value)

Check if value is present.

Set#values()

Return an array of values.

Aliased as .toJSON().

Set#each(fn)

Iterate each member and invoke fn(val).

Set#size()

Return the set size.

Set#clear()

Empty the set and return the old values array.

Set#isEmpty()

Check if the set is empty.

Set#union(set)

Perform a union with set and return a new Set.

Set#intersect(set)

Perform an intersection with set and return a new Set.

Set#clone()

Clone the set and return a new Set of the same values.

License

MIT

About

Set container

Resources

Stars

17 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages