export function sortByNumber ( items , property , direction = "asc" ) { const sortedItems = items . slice ( 0 ) . sort ( ( a , b ) => { let diff = a [ property ] - b [ property ] ; return diff * ( direction === "desc" ? - 1 : 1 ) ; } ) ; return sortedItems ; } export function sortByString ( items , property , direction = "asc" ) { const sortedItems = items . slice ( 0 ) . sort ( ( a , b ) => { let diff = a [ property ] . localeCompare ( b [ property ] ) ; return diff * ( direction === "desc" ? - 1 : 1 ) ; } ) ; return sortedItems ; } export function sortProjectsByFunction ( projects , fn , direction = "desc" ) { const getValue = ( project ) => { const value = fn ( project ) ; return value === undefined ? - Infinity : value ; } ; const sortedProjects = projects . slice ( 0 ) . sort ( function ( a , b ) { let diff = getValue ( a ) - getValue ( b ) ; if ( diff === 0 ) { diff = a . stars - b . stars ; } return diff * ( direction === "desc" ? - 1 : 1 ) ; } ) ; return sortedProjects ; }