Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

diff

v1.0.0arrow_drop_down
v1.0.0
v0.0.1
STATUS
Passing
DOWNLOADS
74
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
2 years ago
SIZE
508 B
Computes the difference between two array references.
2 contributors
Install diff as a package?
Copied
npm i @bit/bit.utils.array.diff
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
src/array/diff.js
16 Lines(5 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** @flow */


/**
 * Computes the difference between two array references. 
 * @name diff
 * @param {[]} firstArray 
 * @param {[]} secondArray
 * @returns {[]} returns an array representing the difference between the two arrays
 * @example
 *  diff([1,2,3], [1,2,3,4,5]) // => [4,5]
 */
export default function diff(firstArray: any[], secondArray: any[]): any[] {
  return firstArray.concat(secondArray).filter((val) => {
    return !(firstArray.includes(val) && secondArray.includes(val));
  });
};