Git Product home page Git Product logo

stable's People

Contributors

domenic avatar mattiasbuelens avatar stephank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stable's Issues

Publish on npm as 1.0.0

While this module has been relatively stable, certain consumers can be reluctant to use it because of the fact that it has not yet entered "stable" stage by semver. Would it be possible to publish this module as 1.0.0 on npm?

package.json "module": "./stable.esm.js" breaks stuff

I'm using accept-language node module which includes stable like this:
var stable = require("stable");

My whole project is bundled and packaged with webpack 4.5, and since this new release it includes require like this:
var stable = webpack_require(/*! stable */ "./node_modules/stable/stable.esm.js");

but unfortanutenaly this leads to "stable is not a function" errors.I guess the problem is that it should actually be a "import stable from.." statemetn instead of the regular requrie to let this work correctly. Or rewrite the stable call to stable.default(args...). I guess there are more situations like this though, and removing the "module" line in package.json fixes everything.

Not quite sure what is the correct approach to handle this. All I know: it doesn't work right now, and stable is the only package in my repro right now that has this kind of issue?

Behaviour when comparator returns NaN

In the case where the comparator returns NaN (such as (A,B) => B-A where either, or both, are undefined) the behaviour of this lib differs from that of vanilla JS:

console.error([1, 2, 3].sort(() => NaN))
console.error(stable.inplace([1, 2, 3], () => NaN))
[ 1, 2, 3 ]
[ 3, 2, 1 ]
console.error([3, 2, 1].sort(() => NaN))
console.error(stable.inplace([3, 2, 1], () => NaN))
[ 3, 2, 1 ]
[ 1, 2, 3 ]

It's really the fault of the comparator function since it should only return a finite number, but in the case where it doesn't, I would argue that it's preferable to treat NaN as 0, so as to not affect the order.

It's unfortunately an easy mistake to make, such as when sorting numerically:

(A, B) => B - A

If either of the values is undefined (or both!) it triggers this issue.

Feature Request: multiple sort parameters

A stable sort is nice because you can sort it over and over again by the same criteria to get nested sort orders.

My question, would it be faster to also enable multiple levels of comparator and run the sort once. The alternative would be to sort and resort with each comparator.

Option 1, multiple levels of comparators

stable.inplace(array, [byName, byValue, byId])

vs Options 2, multiple sorts

stable.inplace(array, byId);
stable.inplace(array, byValue);
stable.inplace(array, byName);

Also would be nice to sort by fields with writing the sort function:
stable.inplace(array, "id");
stable.inplace(array, "value");
stable.inplace(array, "name");

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.