Function reference · Assumptions and sets

difference

Returns the values of the first set that aren't in the second.

Notation

difference(set1, set2)

Write it in an expression: nerdamer('difference({1,2,3},{2})'), or in the Playground.

nerdamer.difference

nerdamer.difference(...args: [a, b]): ParserEntity

A method on the default import. Arguments can be strings, as in Notation.

import { difference }

import { difference } from 'nerdamer/structures';
difference(set1: ParserEntity, set2: ParserEntity): ParserEntity

Import only this function, from nerdamer/structures.

Parameters

set1
The set to take values from.
set2
The values to leave out.

Returns

A set.

Examples

Leave out 2.

difference({1,2,3},{2})
// → {1, 3}
Open in Playground

Sets of symbols work the same way.

difference({x,y},{y})
// → {x}
Open in Playground

Leaving out everything gives the empty set.

difference({1,2},{1,2})
// → {}
Open in Playground

Good to know

  • Both arguments must be sets. The order matters: difference(A,B) keeps what is in A only.

JavaScript examples

nerdamer.difference('{1,2,3}', '{2}').text()
// → {1, 3}

← Back to Function reference