@strong-roots-capital/remove-duplicates-from-sorted
v1.0.0
Published
Remove duplicates from sorted list in-place
Downloads
1
Readme
remove-duplicates-from-sorted
Remove duplicates from sorted list in-place
This code modifies shared data. To minimize the chance of unexpected behavior, fast-check is used for Property-Based Testing of key invariants:
- this function should be idempotent
- this function should not add any elements to the given list
- this function should preserve ordering of the given list
- this function should return the given list without any duplicates
Install
npm install @strong-roots-capital/remove-duplicates-from-sorted
Use
import { removeDuplicatesFromSorted } from '@strong-roots-capital/remove-duplicates-from-sorted'
import randomInt from 'random-int'
const list = Array(10).fill(100).map(randomInt)
const listWithDuplicates = [...list, ...list].sort((x: number, y: number) => x - y)
console.log(listWithDuplicates)
//=>[ 23, 23, 45, 45, 63, 63, 66, 66, 74, 74, 78, 78, 85, 85, 90, 90, 92, 92, 99, 99 ]
console.log(inplaceRemoveDuplicatesFromSorted(listWithDuplicates))
//=>[ 24, 45, 63, 66, 74, 78, 85, 90, 92, 99 ]