param columns function buildColumns ( columns ) { if ( columns . length > 1 && columns . indexOf ( '_source' ) !== - 1 ) { return columns . filter ( ( col ) => col !== '_source' ) ; } else if ( columns . length !== 0 ) { return columns ; } return [ '_source' ] ; } export function addColumn ( columns , columnName ) { if ( columns . includes ( columnName ) ) { return columns ; } return buildColumns ( [ ... columns , columnName ] ) ; } export function removeColumn ( columns , columnName ) { if ( ! columns . includes ( columnName ) ) { return columns ; } return buildColumns ( columns . filter ( ( col ) => col !== columnName ) ) ; } export function moveColumn ( columns , columnName , newIndex ) { if ( newIndex < 0 || newIndex >= columns . length || ! columns . includes ( columnName ) ) { return columns ; } const modifiedColumns = [ ... columns ] ; modifiedColumns . splice ( modifiedColumns . indexOf ( columnName ) , 1 ) ; modifiedColumns . splice ( newIndex , 0 , columnName ) ; return modifiedColumns ; }