DefinitelyTyped/types/compare-function/compare-function-tests.ts
2019-05-24 13:32:28 -07:00

20 lines
376 B
TypeScript

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);