Comments (15)
It currently throws TypeError: Expected a number
.
from num-sort.
I prefer a breaking change.
from num-sort.
Correct
from num-sort.
What is the current behavior?
from num-sort.
What is the reasoning for it being considered lowest rather than highest?
from num-sort.
NaN means not a number which means nothing which means 0.
from num-sort.
Well but 0 is not the lowest possible number 😅
from num-sort.
0 is the smallest natural number and is usually a fallback for NaN
so it's obvious for it to be the smallest number.
from num-sort.
What do you think should be the expected result for [1, -1, NaN].sort(numberSort.ascending)
?
from num-sort.
[NaN, -1, 1]
from num-sort.
So you're treating NaN
as -Infinity
, not 0
.
My opinion is that this is arbitrary and often not intended. How about, instead, adding an option?
const numberSort = require('num-sort');
console.log([1, NaN, -4, 3].sort(numberSort.ascending({ treatNanAs: -Infinity })));
//=> [NaN, -4, 1, 3]
from num-sort.
I agree, NaN
should be last, after -Infinity
.
from num-sort.
So you're treating NaN as -Infinity, not 0.
Infinity is technically a number. NaN is not, hence it should be first/last.
from num-sort.
@sindresorhus Do you prefer a breaking change (simply change the existing behavior) by arbitrarily choosing between first/last, or do you think an option such as I suggested is possible?
from num-sort.
@sindresorhus One last confirmation:
[1, -1, -Infinity, NaN].sort(numberSort.ascending)
//=> [NaN, -Infinity, -1, 1]
[1, -1, -Infinity, NaN].sort(numberSort.descending)
//=> [1, -1, -Infinity, NaN]
Is this correct? If yes I'll submit a PR
from num-sort.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from num-sort.