export function pluck < T , K > ( array , key ) { return array . map ( ( a ) => a [ key ] ) ; } export function shuffle < T > ( array ) { return array . sort ( ( ) => Math . random ( ) - 0.5 ) ; } export function uniq < T > ( array ) { return Array . from ( new Set ( array ) ) ; } export function reduceToObject < T > ( array , key ) { return array . reduce ( ( acc , curr ) => { acc [ curr [ key ] ] = curr ; return acc ; } , { } ) ; } export function groupBy < T > ( array , key ) { return array . reduce ( ( acc , curr ) => { if ( ! acc . hasOwnProperty ( curr [ key ] ) ) { acc [ curr [ key ] ] = [ ] ; } acc [ curr [ key ] ] . push ( curr ) ; return acc ; } , { } as { [ key ] : T [ ] ; } ) ; }