export function flatten < T > ( ... arrays ) { return Array . of < T > ( ) . concat ( ... arrays ) ; } export function definedOf < T > ( ... items ) { return items . filter ( ( i ) => i !== undefined ) . map ( ( i ) => i ! ) ; } declare global { interface Array < T > { choose < U > ( fn ) : U [ ] ; orderBy < U > ( key ) : T [ ] ; } } if ( ! Array . prototype . choose ) { Array . prototype . choose = function < T , U > ( this , fn ) : U [ ] { return this . map ( fn ) . filter ( ( u ) => u !== undefined ) . map ( ( u ) => u ! ) ; } ; } if ( ! Array . prototype . orderBy ) { Array . prototype . orderBy = function < T , U > ( this , key ) : T [ ] { const copy = this . map ( ( e ) => ( { index : key ( e ) , value : e } ) ) ; copy . sort ( ( m1 , m2 ) => ( m1 . index > m2 . index ) ? 1 : ( m1 . index < m2 . index ? - 1 : 0 ) ) ; return copy . map ( ( m ) => m . value ) ; } ; }