export function range ( [ min , max ] , count ) { var output = [ ] ; for ( var i = 0 ; i < count ; i ++ ) output . push ( min + ( max - min ) * i / ( count - 1 ) ) ; return output ; } export function sum < T > ( list , transform ) { for ( var i = 0 , summation = 0 , len = list . length ; i < len ; i ++ ) summation += transform ( list [ i ] ) ; return summation ; } export function find < T > ( list , predicate ) { for ( var i = 0 ; i < list . length ; i ++ ) if ( predicate ( list [ i ] ) ) return list [ i ] ; return undefined ; } export function last < T > ( list ) { return list [ list . length - 1 ] ; } export function hasSubstring ( haystack , needle ) { if ( needle === '' ) return true ; if ( ! haystack ) return false ; return haystack . indexOf ( needle ) !== - 1 ; } export function merged ( a , b ) { function assign ( target , data ) { for ( var key in data ) target [ key ] = data [ key ] ; } var obj = { } ; assign ( obj , a ) ; assign ( obj , b ) ; return obj ; } export function indexBy < T > ( list , key ) { var obj = { } ; for ( var i = 0 ; i < list . length ; i ++ ) obj [ list [ i ] [ key ] as any ] = list [ i ] ; return obj ; } export function uniqueBy < T > ( list , property ) { var seen = { } ; var out = [ ] ; for ( var i = 0 ; i < list . length ; i ++ ) { var key = list [ i ] [ property ] as unknown as string ; if ( ! seen [ key ] ) { seen [ key ] = true ; out . push ( list [ i ] ) ; } } return out ; }