Skip to content

Commit

Permalink
✨ Add array package with xor (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlepage committed Apr 25, 2017
1 parent 954fb15 commit bfa4815
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/array/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import xor from './xor'

export {
xor,
}
5 changes: 5 additions & 0 deletions src/array/xor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import xor from 'lodash/xor'

import update from '../core/update'

export default update(xor)
23 changes: 23 additions & 0 deletions src/array/xor.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-env node, mocha */
import { expect } from 'chai'

import xor from './xor'

describe('Xor', () => {

const withOneAndTwo = { nested: { prop: [1, 2] } }
const oneAndThree = [1, 3]
const withOneAndThree = { nested: { prop: oneAndThree } }
const twoAndThree = [2, 3]
const withTwoAndThree = { nested: { prop: twoAndThree } }

it('should xor arrays', () => {
expect(xor(withOneAndTwo, 'nested.prop', twoAndThree)).to.be.deep.equal(withOneAndThree)
expect(xor(withOneAndTwo, 'nested.prop', oneAndThree)).to.be.deep.equal(withTwoAndThree)
})

it('should xor deep undefined to array', () => {
expect(xor({}, 'nested.prop', oneAndThree)).to.be.deep.equal(withOneAndThree)
expect(xor(undefined, 'nested.prop', oneAndThree)).to.be.deep.equal(withOneAndThree)
})
})
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './core'
export * from './lang'
export * from './array'
4 changes: 2 additions & 2 deletions src/lang/toggle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Toggle', () => {
const withFalse = { nested: { prop: false } }

it('should toggle false to true', () => {
expect(toggle({ nested: { prop: false } }, 'nested.prop')).to.be.deep.equal(withTrue)
expect(toggle(withFalse, 'nested.prop')).to.be.deep.equal(withTrue)
})

it('should toggle falsy to true', () => {
Expand All @@ -25,7 +25,7 @@ describe('Toggle', () => {
})

it('should toggle true to false', () => {
expect(toggle({ nested: { prop: true } }, 'nested.prop')).to.be.deep.equal(withFalse)
expect(toggle(withTrue, 'nested.prop')).to.be.deep.equal(withFalse)
})

it('should toggle truthy to false', () => {
Expand Down

0 comments on commit bfa4815

Please sign in to comment.