param arr returns export function flat < T > ( arr ) { return arr . reduce ( ( flattened , subArr ) => [ ... flattened , ... subArr ] , [ ] ) ; } param arr returns export function unique < T > ( arr ) { return Array . from ( new Set ( arr ) ) ; } param arr returns export function last < T > ( arr ) { return arr . length ? arr [ arr . length - 1 ] : undefined ; } param arr returns export function first < T > ( arr ) { return arr [ 0 ] ; } param arr param chunkSize returns export function splitInChunks < T > ( arr , chunkSize ) { const chunks = [ ] ; if ( arr ) { for ( let i = 0 ; i < arr . length ; i += chunkSize ) { chunks . push ( arr . slice ( i , i + chunkSize ) ) ; } } return chunks ; } param firstOrArray param rest returns export function variadicArgumentToArray < T > ( firstOrArray , rest ) { if ( Array . isArray ( firstOrArray ) ) { return [ ... firstOrArray , ... rest ] ; } return firstOrArray ? [ firstOrArray , ... rest ] : [ ... rest ] ; } param input returns export const flatten = ( input ) : any [ ] => { const flatResult = [ ] ; const stack = [ ... input ] ; while ( stack . length > 0 ) { const current = stack . pop ( ) ; if ( ! Array . isArray ( current ) ) { flatResult . push ( current ) ; } else { stack . push ( ... current ) ; } } return flatResult . reverse ( ) ; } ; param left param right returns export function zip < T > ( left , right ) { const longerArr = left . length > right . length ? left : right ; return longerArr . reduce ( ( zipped , _ , i ) => { const currentZipped = [ ] ; if ( left . length > i ) { currentZipped . push ( left [ i ] ) ; } if ( right . length > i ) { currentZipped . push ( right [ i ] ) ; } return [ ... zipped , ... currentZipped ] ; } , [ ] ) ; } param arr param condition returns export function partition < T > ( arr , condition ) { return arr . reduce ( ( [ conditionTrue , conditionFalse ] , item ) => condition ( item ) ? [ [ ... conditionTrue , item ] , conditionFalse ] : [ conditionTrue , [ ... conditionFalse , item ] ] , [ [ ] , [ ] ] ) ; } param arr param comparator returns export function filterDuplicates < T > ( arr , comparator = ( left , right ) => left === right ) { return arr . filter ( ( item , index ) => ! arr . slice ( 0 , index ) . find ( filteredItem => comparator ( item , filteredItem ) ) ) ; } param arr param comparator returns export function filterDuplicatesRight < T > ( arr , comparator = ( left , right ) => left === right ) { return filterDuplicates ( arr . reverse ( ) , comparator ) . reverse ( ) ; }