Giter VIP home page Giter VIP logo

jims's Introduction

JIMS

Javascript Interactive Merge Sort.

The sorting algorithm where you are the compare function.

Goal

This small JS library is useful when trying to sort or prioritize a list of items for which the comparison operation is transitive but cannot be determined algorithmcally. Ie:

a < b and b < c => a < c

but a computer cannot tell that a < b.

In that case, the two items are displayed to the user which acts as a compare function by selecting which one holds a greater value. Based on these comparisons, the library performs merge sort in the background.

For example, I use it to sort my list of video games played and determine my top 10. You can find the demo here.

Usage

The library can be used a such:

var sorter = new Jims(elements, displayLeft, displayRight, showResult, top);

where

  • elements is an array of elements to sort
  • displayLeft and displayRight are functions taking as a parameter an item out of the elements array and display that element on the left or right side of the screen respectively
  • showResult is the callback function that will be called with the sorted list of elements once the process is done
  • top is an optional parameter indicating that you only care about the top n elements of the array to sort. Note that a smaller top means less comparison for the user as lower valued elements are discarded. By default, top is set to the length of elements

The sorter object then provides two picker functions which you should hook up to the user's click on the left and right side element respectively:

var picker = sorter.pickerFunctions();

$('#left').click(picker.left);
$('#right').click(picker.right);

Once triggered, these picker functions will step forward with the comparison and use the displayLeft and displayRight functions to present a new combination to the user.

jims's People

Contributors

abrochard avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.