param elements param between param final export function joinAnd ( elements , between = ', ' , final = ' and ' ) { if ( elements . length < 2 ) { return elements . join ( "" ) ; } else { const end = elements . length - 1 ; const allButLast = elements . slice ( 0 , end ) ; return allButLast . join ( between ) + final + elements [ end ] ; } } const alphanumericSplitRE = /([0-9]+\.?[0-9]*)/gm ; export function compareAlphanumeric ( string1 , string2 ) { const values1 = string1 . split ( alphanumericSplitRE ) . filter ( Boolean ) ; const values2 = string2 . split ( alphanumericSplitRE ) . filter ( Boolean ) ; if ( values1 . length === 0 && values2 . length === 0 ) { return 0 ; } for ( let index = 0 ; index < values1 . length && index < values2 . length ; ++ index ) { const piece1 = values1 [ index ] ; const piece2 = values2 [ index ] ; if ( piece1 !== piece2 ) { const num1 = parseFloat ( piece1 ) ; const num2 = parseFloat ( piece2 ) ; if ( isNaN ( num1 ) && isNaN ( num2 ) ) { return piece1 . toLowerCase ( ) < piece2 . toLowerCase ( ) ? - 1 : 1 ; } else if ( isNaN ( num1 ) || num1 < num2 ) { return - 1 ; } else if ( isNaN ( num2 ) || num1 > num2 ) { return 1 ; } } } return values2 . length === 0 ? - 1 : values1 . length === 0 ? 1 : values1 . length - values2 . length ; }