Package Exports
- free-dedupe
- free-dedupe/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (free-dedupe) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
free-dedupe
working in progress, coming soon...
De-duplicate (Uniqueify) a arrays with custom logic
install
npm i -S free-dedupe
# yarn add free-dedupeusage
1.commonjs
const dedupe = require('free-dedupe').default;
console.log(dedupe([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4])); // 1,2,3,4don't forget the
.default!!!
2.typescript/esnext
import dedupe from 'free-dedupe';
console.log(dedupe([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4])); // 1,2,3,43.custom logic to detect for duplicates
import dedupe from 'free-dedupe';
console.log(
dedupe(
[ {id:1, name:'Tom'}, {id:2, name:'Tom'}, {id:3, name:'Joe'} ],
(item: any) => item.id
)
); // Tom(id=1), Tom(id=2), Joe(id=3)
console.log(
dedupe(
[ {id:1, name:'Tom'}, {id:2, name:'Tom'}, {id:3, name:'Joe'} ],
[ 'id' ] // 'id'
)
); // Tom(id=1), Tom(id=2), Joe(id=3)API
dedupe(array, getSeedFn)
- array: list of element
- getSeedFn:
- a function whit you custom detect duplicate logic
- a obj key or key list, (key: string| symbol | number )