param { string [ ] } strs return { string } function LongestCommonPerfix ( strs ) { if ( strs . length <= 0 ) { return strs [ 0 ] || '' ; } strs . sort ( ) ; if ( strs [ 0 ] === '' ) { return '' ; } let first = strs [ 0 ] ; let last = strs [ strs . length - 1 ] ; if ( first === last || last . match ( eval ( `/^${ first }/` ) ) ) { return first ; } else { for ( let i = 0 ; i < first . length ; i ++ ) { if ( first [ i ] !== last [ i ] ) { return first . substring ( 0 , i ) ; } } } } export { LongestCommonPerfix } ;