remove-item-array

0.1.3 • Public • Published

remove-item-array

🌪remove array duplicates or customized with JS.

⭐️ Usage

install:

yarn add remove-item-array
npm install remove-item-array --save

use:

const {
    removeItems,
    removeDuplicates
} = require('remove-item-array')

let arr = ['🐏', '🐈', '🐏','🐫','🐈','🐏','🐏','🐈','🐏','🐈','🐫']

// remove all
removeDuplicates(arr)

// or remove '🐏'
removeDuplicates(arr, '🐏')

// remove nums
removeItems(arr, 1, 4)

📦 API

removeDuplicates(arr, item(?))

Removes item duplicates from an array.

Parameters

  • arr: {Array<*>} The target array.
  • item: {<*>} Removes item specified duplicate.

removeItems(arr, start, count)

Performs better to splice, use Proxy can compare splice with removeItems.

Parameters

  • arr: {Array<*>} The target array.
  • start: {Number} start The index to begin removing.
  • count: The count of items need to remove.

💎 Compare

The function that removes all repeating elements, I code four methods, and made a comparison.

The array:

arr = [1, 1, 2, 5, 3, 1, 1, 2, 5, 3, 1, 1, 2, 5, 3, 1, 1, 2, 5, 3, 1, 1, 2, 5, 3, 1, 1, 2, 5, 3, 1, 1, 2, 5, 3]

You can view the results via the https://jsperf.com/removeduplicatesarray

The results:

By comparison, it can be seen that the performance of filter() is better, so the function adopts the filter().

✅ Test

just run

yarn test

📜 MIT

MIT.

Package Sidebar

Install

npm i remove-item-array

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

7.32 kB

Total Files

6

Last publish

Collaborators

  • simida