fork download
  1. const correctOutput = [
  2. '50556 56550',
  3. '3469798283 8382796934',
  4. '193413442071 714203434119',
  5. '173246791 917463217'
  6. ];
  7.  
  8. const input = [
  9. '5 56 50',
  10. '79 82 34 83 69',
  11. '420 34 19 71 341',
  12. '17 32 91 7 46'
  13. ];
  14.  
  15. let compare, sort, work;
  16.  
  17. compare = function(intA, intB) {
  18. intA = intA.toString();
  19. intB = intB.toString();
  20. if (parseInt(intA + intB) < parseInt(intB + intA))
  21. return -1;
  22. return 1;
  23. };
  24.  
  25. sort = function(ints) {
  26. let max, min;
  27. min = ints.sort(compare);
  28. max = min.slice(0).reverse();
  29. return [min, max];
  30. };
  31.  
  32. work = function() {
  33. let output;
  34.  
  35. for (let i = 0; i < input.length; i++) {
  36. output = sort(input[i].split(' '));
  37. output = output[0].join('') + ' ' + output[1].join('');
  38. console.log(`[${input[i]}] ${output}: ${output === correctOutput[i] ? 'right' : 'wrong'}`);
  39. }
  40. };
  41.  
  42. work();
Success #stdin #stdout 0.04s 122240KB
stdin
Standard input is empty
stdout
[5 56 50] 50556 56550: right
[79 82 34 83 69] 3469798283 8382796934: right
[420 34 19 71 341] 193413442071 714203434119: right
[17 32 91 7 46] 173246791 917463217: right