3.0.0 • Published 3 years ago

@writetome51/array-remove-all-of-first-of v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

removeFirstOf\<T>(     value: T,     array: T[]): void

Removes the first instance of value from array.

removeAllOf\<T>(     value: T,     array: T[]): void

Removes all instances of value from array.

removeAllOfEach\<T>(     values: T[],     array: T[]): void

Removes all instances of each value in values from array.

All the functions use identical === to find matches, except when the value being search for is an array. Arrays must only have identical content to be a match (see examples).

Examples

let arr = ['a', 'b', 'c', 'a', 'b', 'c'];
removeFirstOf('c', arr);
// arr is now ['a', 'b', 'a', 'b', 'c']

arr = ['a', 'b', 'c', 'a', 'b', 'c'];
removeAllOf('c', arr);
// arr is now ['a', 'b', 'a', 'b']

arr = ['a', 'b', 'c', 1, 2, 3, 'a', 'b', 'c'];
removeAllOfEach(['a', 'b', 'c'], arr);
// arr is now [1, 2, 3]

const obj = {name: 'steve'};
arr = [obj, {name: 'steve'}];
removeAllOf(obj, arr);
// arr is now [{name: 'steve'}]

// All the functions use identical `===` to find matches, except when the 
// value being search for is an array. Arrays must only have identical 
// content to be a match:

arr = [[1,2], [3,4], [1,2]];
removeFirstOf([1,2], arr);
// arr is now [ [3,4], [1,2] ]

const obj = {name: 'steve'};
arr = [ [obj], [{name: 'steve'}] ];
removeAllOf([obj], arr);
// arr is now [ [{name: 'steve'}] ]

Installation

npm i @writetome51/array-remove-all-of-first-of'

Loading

import {removeFirstOf, removeAllOf, removeAllOfEach} 
    from '@writetome51/array-remove-all-of-first-of';