DefinitelyTyped/types/compare-function/compare-function-tests.ts

20 lines
376 B
TypeScript
Raw Normal View History

2019-05-24 20:32:28 +00:00
import compare = require('compare-function');
const songs = [{
artist: 'Joy Division',
track: 'Warsaw'
}, {
artist: 'New Order',
track: 'Blue Monday'
}, {
artist: 'Freebass',
track: 'Plan B'
}];
function artist(song: {artist: string}) {
return song.artist;
}
songs.sort(compare(artist)).map(artist);
songs.sort(compare(-1, artist)).map(artist);