Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Commit d127550

Browse files
authored
Merge pull request #2 from poverenje/develop
Add a function to create a linked instance
2 parents 763cb44 + 728a41d commit d127550

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/create.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { sort } from './sort';
2+
import { insert } from './insert';
3+
import { search } from './search';
4+
import type { Comparator } from './types';
5+
6+
export function create<T>(array: T[], cmp: Comparator<T>) {
7+
const sortedArray = sort(array, cmp);
8+
9+
return {
10+
array: sortedArray,
11+
insert: (element: T) => insert(sortedArray, element, cmp),
12+
search: (element: T) => search(sortedArray, element, cmp),
13+
}
14+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export { sort } from './sort';
22
export { insert } from './insert';
33
export { search } from './search';
44
export { numberCmp } from './cmp';
5+
export { create } from './create';
56
export type { Comparator } from './types';

0 commit comments

Comments
 (0)