Skip to content

Instantly share code, notes, and snippets.

@stefanmaric
Created July 26, 2018 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanmaric/9e5191c7c19a3ae2200830ae6254f574 to your computer and use it in GitHub Desktop.
Save stefanmaric/9e5191c7c19a3ae2200830ae6254f574 to your computer and use it in GitHub Desktop.
Alternatives for exclusion with lodash
import * as _ from 'lodash'
const exclusion = (...arrays) =>
_.flatMap(arrays, x => _.difference(x, ..._.without(arrays, x)))
import * as _ from 'lodash'
const exclusion = (...arrays) =>
_.difference(
_.union(...arrays),
_.flattenDepth(
_.map(arrays, x =>
_.map(_.without(arrays, x), y => _.intersection(x, y))
),
2
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment