1.0.0 • Published 1 year ago

@aneyman/comparison-sort v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Comparison Sort

A TypeScript library for optimal sorting through pairwise comparisons. Perfect for implementing ranking systems where items need to be compared one pair at a time.

Installation

npm install @aneyman/comparison-sort

Usage

import { OptimalSort, ComparisonResult } from '@aneyman/comparison-sort';

// Initialize with items
const sorter = new OptimalSort({
  items: [
    { item: { id: '1', title: 'Item 1' }, position: 0 },
    { item: { id: '2', title: 'Item 2' }, position: 1 }
  ],
  newItem: { id: '3', title: 'Item 3' }
});

// Get next comparison
const comparison = sorter.getNextComparison();

// Submit comparison result
sorter.submitComparison(
  comparison.item1, 
  comparison.item2, 
  ComparisonResult.BETTER
);

// Check if sorting is complete
if (sorter.isSortingComplete()) {
  const sortedItems = sorter.getSortedItems();
  console.log(sortedItems);
}

Features

  • Optimal pairwise comparison sorting
  • Support for equal items
  • TypeScript support
  • Minimal number of comparisons needed
  • Maintains transitivity

License

MIT

1.0.0

1 year ago