Array Difference Utility

0.0.2 · abandoned · verified Sun Apr 19

The `array-difference` package, currently at version 0.0.2 and last published in 2020 (with a copyright date of 2013), provides a basic utility method for computing the symmetric difference between two arrays. It identifies elements present in one array but not the other. Originally designed to be compatible with AMD and CommonJS modules, it functions in both Node.js and browser environments of its era. This package is no longer actively maintained or developed. Modern JavaScript projects typically use native `Set` operations, `filter` with `includes`, or more feature-rich, actively maintained third-party libraries that offer advanced array comparison, custom comparison functions, and better performance for large datasets. Its key differentiator is its simplicity and small footprint, though this comes at the cost of modern features and ongoing support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `difference` function to find elements unique to two given arrays.

const difference = require('array-difference');

const array1 = [1, 2, 3, 'a', 'b'];
const array2 = [2, 3, 4, 'b', 'c'];

// Compute the symmetric difference: elements unique to array1 or array2
const diffResult = difference(array1, array2);

console.log('Array 1:', array1);
console.log('Array 2:', array2);
console.log('Difference (elements unique to either array):', diffResult);
// Expected output: [1, 4, 'a', 'c']

const array3 = [5, 6, 7];
const array4 = [6, 8];
console.log('Difference ([5, 6, 7], [6, 8]):', difference(array3, array4));
// Expected output: [5, 7, 8]

view raw JSON →