-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* differenceBy * differenceWith * dropRight * dropWhile * dropRightWhile * fill * intersection * intersectionBy * intersectionWith * pullAll * pullAllBy * pullAllWith * pullAt * reverse * slice * union * unionBy * unionWith * xorBy * xorWith * without
- Loading branch information
Showing
44 changed files
with
598 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _differenceBy from 'lodash/differenceBy' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* This method is like {@link array.difference} except that it uses <code>iteratee</code> to generate the value to be compared for each element. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {...Array} values The arrays of values to exclude. | ||
* @param {Function} [iteratee={@link https://lodash.com/docs#identity|lodash.identity}] The iteratee invoked per element. | ||
* @return {Object} Returns the updated object. | ||
* @example differenceBy({ nested: { prop: [1.2, 3.4, 5.6] } }, 'nested.prop', [5.4, 2.1], Math.floor) // => { nested: { prop: [1.2, 3.4] } } | ||
* @see {@link https://lodash.com/docs#differenceBy|lodash.differenceBy} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const differenceBy = convert(_differenceBy) | ||
export { differenceBy, differenceBy as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { differenceBy } from './differenceBy' | ||
|
||
describe('DifferenceBy', () => { | ||
|
||
it('should remove intersecting elements according to iteratee', () => { | ||
expect(differenceBy({ nested: { prop: [1.2, 3.4, 5.6] } }, 'nested.prop', [5.4, 2.1], Math.floor)).toEqual({ nested: { prop: [1.2, 3.4] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _differenceWith from 'lodash/differenceWith' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* This method is like {@link array.difference} except that it uses <code>comparator</code> to compare elements of the former array to <code>values</code>. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {...Array} values The arrays of values to exclude. | ||
* @param {Function} [comparator] The comparator invoked per element. | ||
* @return {Object} Returns the updated object. | ||
* @example differenceWith({ nested: { prop: [{ x: 1 }, { x: 2 }] } }, 'nested.prop', [{ x: 2 }, { x: 3 }], (a, b) => a.x === b.x) // => { nested: { prop: [{ x: 1 }] } } | ||
* @see {@link https://lodash.com/docs#differenceWith|lodash.differenceWith} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const differenceWith = convert(_differenceWith) | ||
export { differenceWith, differenceWith as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { differenceWith } from './differenceWith' | ||
|
||
describe('DifferenceWith', () => { | ||
|
||
it('should remove intersecting elements according to iteratee', () => { | ||
expect(differenceWith({ nested: { prop: [{ x: 1 }, { x: 2 }] } }, 'nested.prop', [{ x: 2 }, { x: 3 }], (a, b) => a.x === b.x)).toEqual({ nested: { prop: [{ x: 1 }] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _dropRight from 'lodash/dropRight' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* Replaces an array dropping one or several elements at the end of the former array. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {number} [n=1] The number of elements to drop. | ||
* @return {Object} Returns the updated object. | ||
* @example dropRight({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 2) // => { nested: { prop: [1, 2] } } | ||
* @see {@link https://lodash.com/docs#dropRight|lodash.dropRight} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const dropRight = convert(_dropRight) | ||
export { dropRight, dropRight as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { dropRight } from './dropRight' | ||
|
||
describe('DropRight', () => { | ||
|
||
it('should drop several elements at the end of the array', () => { | ||
expect(dropRight({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 2)).toEqual({ nested: { prop: [1, 2] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _dropRightWhile from 'lodash/dropRightWhile' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* Replaces an array excluding elements dropped from the end. Elements are dropped until <code>predicate</code> returns falsey. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {Function} [predicate={@link https://lodash.com/docs#identity|lodash.identity}] The function invoked per iteration. | ||
* @return {Object} Returns the updated object. | ||
* @example dropRightWhile({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v > 2) // => { nested: { prop: [1, 2] } } | ||
* @see {@link https://lodash.com/docs#dropRightWhile|lodash.dropRightWhile} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const dropRightWhile = convert(_dropRightWhile) | ||
export { dropRightWhile, dropRightWhile as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { dropRightWhile } from './dropRightWhile' | ||
|
||
describe('DropRightWhile', () => { | ||
|
||
it('should drop elements > 2 at the end of the array', () => { | ||
expect(dropRightWhile({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v > 2)).toEqual({ nested: { prop: [1, 2] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _dropWhile from 'lodash/dropWhile' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* Replaces an array excluding elements dropped from the beginning. Elements are dropped until <code>predicate</code> returns falsey. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {Function} [predicate={@link https://lodash.com/docs#identity|lodash.identity}] The function invoked per iteration. | ||
* @return {Object} Returns the updated object. | ||
* @example dropWhile({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v < 3) // => { nested: { prop: [3, 4] } } | ||
* @see {@link https://lodash.com/docs#dropWhile|lodash.dropWhile} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const dropWhile = convert(_dropWhile) | ||
export { dropWhile, dropWhile as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import dropWhile from './dropWhile' | ||
|
||
describe('DropWhile', () => { | ||
|
||
it('should drop elements < 3 at the beginning of the array', () => { | ||
expect(dropWhile({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v < 3)).toEqual({ nested: { prop: [3, 4] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import _fill from 'lodash/fill.js' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* Replaces by an array filled with value from start up to, but not including, end. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {*} value The value to fill array with. | ||
* @param {number} [start=0] | ||
* @param {number} [end=array.length] | ||
* @return {Object} Returns the updated object. | ||
* @example fill({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 6, 1, 3) // => { nested: { prop: [1, 6, 6, 4] } } | ||
* @see {@link https://lodash.com/docs#fill|lodash.fill} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const fill = convert(_fill) | ||
export { fill, fill as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { fill } from './fill' | ||
|
||
describe('Fill', () => { | ||
|
||
it('should fill array with 6 from 1 to 3 excluded', () => { | ||
expect(fill({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 6, 1, 3)).toEqual({ nested: { prop: [1, 6, 6, 4] } }) // 🍺 | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _intersection from 'lodash/intersection' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* Replaces by an array of unique values that are included in th former array and all given arrays. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {...Array} [arrays] The arrays to inspect. | ||
* @return {Object} Returns the updated object. | ||
* @example intersection({ nested: { prop: [1, 2] } }, 'nested.prop', [2, 3]) // => { nested: { prop: [2] } } | ||
* @see {@link https://lodash.com/docs#intersection|lodash.intersection} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const intersection = convert(_intersection) | ||
export { intersection, intersection as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { intersection } from './intersection' | ||
|
||
describe('Intersection', () => { | ||
|
||
it('should replace by intersection of arrays', () => { | ||
expect(intersection({ nested: { prop: [1, 2] } }, 'nested.prop', [2, 3])).toEqual({ nested: { prop: [2] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _intersectionBy from 'lodash/intersectionBy' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* This method is like {@link array.intersection} except that it uses <code>iteratee</code> to generate the value to be compared for each element. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {...Array} [arrays] The arrays to inspect. | ||
* @param {Function} [iteratee={@link https://lodash.com/docs#identity|lodash.identity}] The iteratee invoked per element. | ||
* @return {Object} Returns the updated object. | ||
* @example intersectionBy({ nested: { prop: [1.2, 2.1] } }, 'nested.prop', [2.3, 3.2], Math.floor) // => { nested: { prop: [2.1] } } | ||
* @see {@link https://lodash.com/docs#intersectionBy|lodash.intersectionBy} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const intersectionBy = convert(_intersectionBy) | ||
export { intersectionBy, intersectionBy as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { intersectionBy } from './intersectionBy' | ||
|
||
describe('IntersectionBy', () => { | ||
|
||
it('should replace by intersection of arrays', () => { | ||
expect(intersectionBy({ nested: { prop: [1.2, 2.1] } }, 'nested.prop', [2.3, 3.2], Math.floor)).toEqual({ nested: { prop: [2.1] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _intersectionWith from 'lodash/intersectionWith' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* This method is like {@link array.intersection} except that it uses <code>comparator</code> to compare elements of the former array to <code>arrays</code>. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {...Array} [arrays] The arrays to inspect. | ||
* @param {Function} [comparator] The comparator invoked per element. | ||
* @return {Object} Returns the updated object. | ||
* @example intersectionWith({ nested: { prop: [{ x: 1 }, { x: 2 }] } }, 'nested.prop', [{ x: 2 }, { x: 3 }], (a, b) => a.x === b.x) // => { nested: { prop: [{ x: 2 }] } } | ||
* @see {@link https://lodash.com/docs#intersectionWith|lodash.intersectionWith} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const intersectionWith = convert(_intersectionWith) | ||
export { intersectionWith, intersectionWith as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { intersectionWith } from './intersectionWith' | ||
|
||
describe('IntersectionWith', () => { | ||
|
||
it('should replace by intersection of arrays', () => { | ||
expect(intersectionWith({ nested: { prop: [{ x: 1 }, { x: 2 }] } }, 'nested.prop', [{ x: 2 }, { x: 3 }], (a, b) => a.x === b.x)).toEqual({ nested: { prop: [{ x: 2 }] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _pullAll from 'lodash/pullAll' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* This method is like {@link array.pull} except that it accepts an array of values to remove. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {Array} values The values to remove. | ||
* @return {Object} Returns the updated object. | ||
* @example pullAll({ nested: { prop: [1, 2, 3, 1, 2, 3] } }, 'nested.prop', [1, 3]) // => { nested: { prop: [2, 2] } } | ||
* @see {@link https://lodash.com/docs#pullAll|lodash.pullAll} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const pullAll = convert(_pullAll) | ||
export { pullAll, pullAll as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { pullAll } from './pullAll' | ||
|
||
describe('PullAll', () => { | ||
|
||
it('should remove several matching elements', () => { | ||
expect(pullAll({ nested: { prop: [1, 2, 3, 1, 2, 3] } }, 'nested.prop', [1, 3])).toEqual({ nested: { prop: [2, 2] } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _pullAllBy from 'lodash/pullAllBy' | ||
import { convert } from '../util/convert' | ||
|
||
/** | ||
* This method is like {@link array.pullAll} except that it accepts <code>iteratee</code> to generate the criterion by which each element is compared. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {Array} values The values to remove. | ||
* @param {Function} [iteratee={@link https://lodash.com/docs#identity|lodash.identity}] The iteratee invoked per element. | ||
* @return {Object} Returns the updated object. | ||
* @example pullAllBy({ nested: { prop: [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }, { x: 2 }, { x: 3 }] } }, 'nested.prop', [{ x: 1 }, { x: 3 }], 'x') // => { nested: { prop: [{ x: 2 }, { x: 2 }] } } | ||
* @see {@link https://lodash.com/docs#pullAllBy|lodash.pullAllBy} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const pullAllBy = convert(_pullAllBy) | ||
export { pullAllBy, pullAllBy as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env jest */ | ||
import { pullAllBy } from './pullAllBy' | ||
|
||
describe('PullAllBy', () => { | ||
|
||
it('should remove several matching elements', () => { | ||
expect(pullAllBy({ nested: { prop: [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }, { x: 2 }, { x: 3 }] } }, 'nested.prop', [{ x: 1 }, { x: 3 }], 'x')).toEqual({ nested: { prop: [{ x: 2 }, { x: 2 }] } }) | ||
}) | ||
}) |
Oops, something went wrong.