const doCombine = < T > ( items , remaining , combination , result ) : void => { if ( remaining === 0 ) { if ( combination . length > 0 ) { result . push ( combination ) ; } return ; } for ( let i = 0 ; i < items . length ; i ++ ) { doCombine ( items . slice ( i + 1 ) , remaining - 1 , combination . concat ( [ items [ i ] ] ) , result ) ; } return ; } ; /**
 * Build all combinations of items with the specified size.
 */ export const combine = < T > ( items , size ) : T [ ] [ ] => { const result = [ ] ; doCombine ( items , size , [ ] , result ) ; return result ; } ;