export function removeFromArray < T > ( array , item ) { return array . filter ( value => value !== item ) ; } export function arrayToRecord < T > ( array , keySelector ) { return array . reduce ( ( res , value ) => ( { ... res , [ keySelector ( value ) ] : value } ) , { } ) ; } export function replace < T > ( array , index , item ) { return [ ... array . slice ( 0 , index ) , item , ... array . slice ( index + 1 ) ] ; } export function swap < T > ( array , index1 , index2 ) { const lowIndex = Math . min ( index1 , index2 ) ; const highIndex = Math . max ( index1 , index2 ) ; const item1 = array [ lowIndex ] ; const item2 = array [ highIndex ] ; return [ ... array . slice ( 0 , lowIndex ) , item2 , ... array . slice ( lowIndex + 1 , highIndex ) , item1 , ... array . slice ( highIndex + 1 ) ] ; }