lightness / type-comparator Goto Github PK
View Code? Open in Web Editor NEWUseful comparator functions written on Typescript
License: MIT License
Useful comparator functions written on Typescript
License: MIT License
const array = [
{ name: 'Mission1', value: 1, isGeted:true, isFinish:true },
{ name: 'Mission2', value: 2, isGeted:false, isFinish:true },
{ name: 'Mission3', value: 3, isGeted:false, isFinish:false },
{ name: 'Mission4', value: 4, isGeted:false, isFinish:false},
];
I want get the result like this:
const array = [
{ name: 'Mission2', value: 2, isGeted:false, isFinish:true },
{ name: 'Mission4', value: 4, isGeted:false, isFinish:false},
{ name: 'Mission3', value: 3, isGeted:false, isFinish:false },
{ name: 'Mission1', value: 1, isGeted:true, isFinish:true },
];
Means the finish mission is in the top. But when "isGeted" is true, it will move to the bottom.
At last, other missions will sort by value desc.
I write this:
comparator = queue([
map(m => m.isGeted, asc),
map(m => m.isFinish, desc),
map(m => m.value, desc)
]);
but the result is:
[
{ name: 'Mission2', value: 2, isGeted:false, isFinish:true },
{ name: 'Mission1', value: 1, isGeted:true, isFinish:true },
{ name: 'Mission4', value: 4, isGeted:false, isFinish:false},
{ name: 'Mission3', value: 3, isGeted:false, isFinish:false },
];
How should I write to get the results I want?
IMHO it's really useful to have operator .exclude(values: string | string[])
, which will sort values
with maximum priority
For example:
const a = [
"--",
"a",
"b"
]
// a = ['a', 'b', '--']
a.sort(cmp().exclude('--').use(asc));
It's really more obvious :)
I think the latest release is missing its build
directory, which causes TS to fail to import anything.
The error message I get is Cannot find module 'type-comparator' or its corresponding type declarations.ts(2307)
Skimming the Github workflows file, it looks like there's no npm build
step being called anywhere, just install and publish
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.