Skip to content

Instantly share code, notes, and snippets.

@forrest-akin
Last active September 26, 2020 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forrest-akin/56c88e4f82d36c92e37dd251ccc1718b to your computer and use it in GitHub Desktop.
Save forrest-akin/56c88e4f82d36c92e37dd251ccc1718b to your computer and use it in GitHub Desktop.
const largestNumber =
xs =>
headIsZero(
mapInPlace( toString , xs )
.sort( byBestOrderForLargestNumber ) )
? '0'
: xs.join( '' )
const byBestOrderForLargestNumber =
( x , y ) => x + y < y + x || -1
const mapInPlace =
( f , xs ) =>
( xs.forEach( ( x , i ) => xs[ i ] = f( x ) )
, xs )
const toString =
x => x.toString()
const headIsZero =
( [ x ] ) => x === '0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment