sort-all-in-one

1.0.13 • Public • Published

sort-all-in-one

A lite, tinny package that is less than 20 KB in size.

Dependencies:

momentjs

Overview:

A sorting package that gives the option to sort array of objects sort with several alogithms based on any key of that objects. currently we are offering the several algorithms

  • Bubble Sort
  • Selection Sort
  • Merge Sort
  • Quick Sort
  • Insertion Sort

Features:

  • Collection sorting (array of objects)
  • Based on Any key
  • Date type key based sorting

Installation:

npm install sort-all-in-one

Usage:

const languages = [
  {
    name: 'C',
    year: 1972
  },
  {
    name: 'C#',
    year: 2000
  },
  {
    name: 'C++',
    year: 1983
  },
  {
    name: 'Clojure',
    year: 2007
  },
  {
    name: 'Elm',
    year: 2012
  },
  {
    name: 'Go',
    year: 2009
  }
];

If you want to sort the array of objects based on its key name or based on its key year

let opts = {
  algo: 'default',    // bubble,selection,insertion,quick,merge
  array: languages,
  key: 'year',
  orderBy: 'desc',      // asc,desc
  date: true,          // if the key is a date or false if not
},
 
const Sorting = new NpmSorting();
const sortedList = Sorting.sort(opts);

If you want to fetch the number of comparisons done in sorting the data just use compareCount() method. Example Code:

let opts = {
  algo: 'default',    // bubble,selection,insertion,quick,merge
  array: languages,
  key: 'year',
  orderBy: 'desc',      // asc,desc
  date: true,          // if the key is a date or false if not
},
 
const Sorting = new NpmSorting();
const sortedList = Sorting.sort(opts);
const count = Sorting.compareCount();

Demo

Coming Soon

Contributer

The original author is Rafi Ud Daula Refat and Mashuk Sadman

Package Sidebar

Install

npm i sort-all-in-one

Weekly Downloads

0

Version

1.0.13

License

ISC

Last publish

Collaborators

  • abnormalz
  • halumz
  • onlyrefat