https://github.com/writetome51/array-get-and-remove-duplicates
Removes and returns every extra instance of each array item
https://github.com/writetome51/array-get-and-remove-duplicates
array-manipulations javascript remove remove-duplicates typescript
Last synced: 3 months ago
JSON representation
Removes and returns every extra instance of each array item
- Host: GitHub
- URL: https://github.com/writetome51/array-get-and-remove-duplicates
- Owner: writetome51
- License: mit
- Created: 2018-11-08T07:41:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-15T00:54:48.000Z (about 7 years ago)
- Last Synced: 2025-01-02T07:25:59.523Z (over 1 year ago)
- Topics: array-manipulations, javascript, remove, remove-duplicates, typescript
- Language: TypeScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getAndRemoveDuplicates(array): any[]
Removes and returns every extra instance of unique items in `array`.
NOTICE: The function will error if `array` contains an object.
'object' does not include arrays. Arrays are OK.
## Examples
```
let arr = [1, 2, 3, 4, 1, 2, 3, 4, 5, 2];
let duplicates = getAndRemoveDuplicates(arr);
// arr is now [1,2,3,4,5].
// duplicates is now [1,2,2,3,4]
// (In returned duplicates, identical items are always side-by-side)
let arr = [1, 2, ['a','b'], 9, 1, 2, 3, 4, ['a','b'], 1, 9, ['a','b']];
let duplicates = getAndRemoveDuplicates(arr);
// arr is now [1, 2, ['a','b'], 9, 3, 4]
// duplicates is now [1, 1, 2, ['a','b'], ['a','b'], 9]
// This will trigger error, because arr contains object:
let arr = [1, 2, {prop:1}, 2, 3, 4];
getAndRemoveDuplicates(arr); // Error!
```
## Installation
`npm install @writetome51/array-get-and-remove-duplicates`
## Loading
```
// If using TypeScript:
import {getAndRemoveDuplicates} from '@writetome51/array-get-and-remove-duplicates';
// If using ES5 JavaScript:
var getAndRemoveDuplicates =
require('@writetome51/array-get-and-remove-duplicates').getAndRemoveDuplicates;
```