Skip to main content
added 553 characters in body
Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90

#JavaScript (ES6) 54 72 7285

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.
Note 2: the newline inside `` is significant and must be counted

Edit Don't argue with a moderator (...just kidding)

Edit2 Fixed I/O format using popups (see Default for Code Golf: Input/Output methods)

// Complete program with I/O
// The sorting function is shorter as input are strings

alert((l=prompt().split(' ')).sort((a,b)=>a+b>b+a).join('')+`
`+l.reverse().join(''))

// Testable function (67 chars)
// With an integer array parameter, the sorting function must convert to string 

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+`
`+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509
95021

50556
56550

3652526
5265236

3652525
5255236

3652452
5252436

#JavaScript (ES6) 54 72

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.

Edit Don't argue with a moderator (...just kidding)

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+`
`+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509
95021

50556
56550

3652526
5265236

3652525
5255236

3652452
5252436

#JavaScript (ES6) 54 72 85

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.
Note 2: the newline inside `` is significant and must be counted

Edit Don't argue with a moderator (...just kidding)

Edit2 Fixed I/O format using popups (see Default for Code Golf: Input/Output methods)

// Complete program with I/O
// The sorting function is shorter as input are strings

alert((l=prompt().split(' ')).sort((a,b)=>a+b>b+a).join('')+`
`+l.reverse().join(''))

// Testable function (67 chars)
// With an integer array parameter, the sorting function must convert to string 

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+`
`+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509
95021

50556
56550

3652526
5265236

3652525
5255236

3652452
5252436

added 64 characters in body
Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90

#JavaScript (ES6) 54 72

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.

Edit Don't argue with a moderator (...just kidding)

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+' '+l+`
`+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509 95021
50556 5655095021

50556
3652526 526523656550

3652526
3652525 52552365265236

3652525
3652452 52524365255236

3652452
5252436

#JavaScript (ES6) 54 72

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+' '+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509 95021
50556 56550
3652526 5265236
3652525 5255236
3652452 5252436

#JavaScript (ES6) 54 72

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.

Edit Don't argue with a moderator (...just kidding)

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+`
`+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509
95021

50556
56550

3652526
5265236

3652525
5255236

3652452
5252436

Post Undeleted by edc65
added 315 characters in body
Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90

#JavaScript (ES6) 5454 72

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.

F=l=>alertF=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+' '+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509 95021

55056 56505
50556 56550
3652526 5265236
3652525 5255236
3652452 5252436

#JavaScript (ES6) 54

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong

F=l=>alert(l.sort().join('')+' '+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])

12509 95021

55056 56505

#JavaScript (ES6) 54 72

That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.

Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+' '+l.reverse().join(''))

Test In Firefox / FireBug console

F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509 95021
50556 56550
3652526 5265236
3652525 5255236
3652452 5252436

added 31 characters in body
Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90
Loading
Post Deleted by edc65
Source Link
edc65
  • 32.2k
  • 3
  • 36
  • 90
Loading