Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/setIntersection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function setIntersecion(firstSet, secondSet) {

const intersection = new Set([...firstSet].filter(x => secondSet.includes(x)))

if (!firstSet || !secondSet) {
return undefined
} return Array.from(intersection)
}
24 changes: 24 additions & 0 deletions test/setIntersection_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import setIntersection from '../src/setIntersection';

describe('setIntersection()', () => {
it('should be a function', () => {
expect(setIntersection).to.be.a('function');
});

it('Return the intersection of two sets.', () => {
const firstSet = [1, 2, 3, 4];
const secondSet = [2, 4, 6, 8];
expect(setIntersection(firstSet, secondSet)).to.deep.equal([2, 4]);
});

it('Return the intersection of two sets.', () => {
const firstSet = [3, 6, 9, 12];
const secondSet = [6, 7, 8, 9];
expect(setIntersection(firstSet, secondSet)).to.deep.equal([6, 9]);
});

it('Will not try to evaluate empty things', () => {
expect(setIntersection('', '')).to.equal(undefined);
});
});