Skip to content

Commit

Permalink
feat: update to support CommonJS + update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vinroger committed Aug 28, 2024
1 parent 1e03da6 commit 22faec1
Show file tree
Hide file tree
Showing 19 changed files with 477 additions and 154 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
.npmrc
.npmrc

dist
node_modules
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts
src
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ Install quick-median with npm:
npm install quick-median
```

### CommonJS
```javascript
const { findMedian } = require('quick-median');

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const median = findMedian(arr);
console.log(median); // 5.5
```

### ES Module (TypeScript Supported)
```javascript
import findMedian from 'quick-median';

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const median = findMedian(arr);
console.log(median); // 5.5

```

## Why this project?

Many existing median-finding packages on npm are not optimized for performance. This project implements the Floyd-Rivest algorithm, a highly efficient selection algorithm that outperforms traditional quickselect in practice.
Expand Down
1 change: 0 additions & 1 deletion dist/cjs/index.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findMedian = findMedian;
function SELECT(X, L, R, K) {
while (R > L) {
if (R - L > 600) {
Expand Down
1 change: 0 additions & 1 deletion dist/esm/index.d.ts

This file was deleted.

56 changes: 0 additions & 56 deletions dist/esm/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.d.ts

This file was deleted.

56 changes: 0 additions & 56 deletions dist/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.min.js

This file was deleted.

Loading

0 comments on commit 22faec1

Please sign in to comment.