import zipWith from 'lodash/zipWith' ; import uniq from 'lodash/uniq' ; import compact from 'lodash/compact' ; import flatten from 'lodash/flatten' ; import type { WellOrderOption } from '../types' ; const _orderingColsToRows = ( ordering ) : string [ ] [ ] => zipWith ( ... ordering , ( ... col ) => compact ( uniq ( col ) ) ) ; export const orderWells = ( defaultOrdering , first , second ) : string [ ] => { let orderedWells = [ ] ; if ( first === 't2b' ) { if ( second === 'l2r' ) { orderedWells = defaultOrdering ; } else if ( second === 'r2l' ) { orderedWells = defaultOrdering . slice ( ) . reverse ( ) ; } } else if ( first === 'b2t' ) { if ( second === 'l2r' ) { orderedWells = defaultOrdering . map ( col => col . slice ( ) . reverse ( ) ) ; } else if ( second === 'r2l' ) { orderedWells = defaultOrdering . slice ( ) . reverse ( ) . map ( col => col . slice ( ) . reverse ( ) ) ; } } else if ( first === 'l2r' ) { if ( second === 't2b' ) { orderedWells = _orderingColsToRows ( defaultOrdering ) ; } else if ( second === 'b2t' ) { orderedWells = _orderingColsToRows ( defaultOrdering ) . slice ( ) . reverse ( ) ; } } else if ( first === 'r2l' ) { if ( second === 't2b' ) { orderedWells = _orderingColsToRows ( defaultOrdering ) . map ( col => col . slice ( ) . reverse ( ) ) ; } else if ( second === 'b2t' ) { orderedWells = _orderingColsToRows ( defaultOrdering ) . slice ( ) . reverse ( ) . map ( col => col . slice ( ) . reverse ( ) ) ; } } return flatten ( orderedWells ) ; } ;