loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7379555143330747","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgbGFyZ2VzdE51bWJlciA9IChudW1BcnIpID0+IHsNCiBudW1BcnIuc29ydCgoYSwgYikgPT4gew0KICAgIGlmKGEgPT0gYil7DQogICAgICByZXR1cm4gMDsNCiAgICB9ICAgICAgIA0KICAgIGEgPSBhLnRvU3RyaW5nKCkuc3BsaXQoJycpOw0KICAgIGIgPSBiLnRvU3RyaW5nKCkuc3BsaXQoJycpOyAgICAgDQogICAgY29uc3QgbWF4TGVuZ3RoID0gYS5sZW5ndGggPiBiLmxlbmd0aCA/IGEubGVuZ3RoIDogYi5sZW5ndGg7ICAgICAgICANCiAgICBmb3IobGV0IGkgPSAwOyBpIDwgbWF4TGVuZ3RoOyBpKyspew0KICAgICAgaWYoIWFbaV0pew0KICAgICAgICBhW2ldID0gYVtpLTFdOw0KICAgICAgfQ0KICAgICAgaWYoIWJbaV0pew0KICAgICAgICBiW2ldID0gYltpLTFdOw0KICAgICAgfQ0KICAgICAgaWYocGFyc2VJbnQoYVtpXSkgPiBwYXJzZUludChiW2ldKSl7DQogICAgICAgICAgcmV0dXJuIC0xOw0KICAgICAgfWVsc2UgaWYocGFyc2VJbnQoYVtpXSkgPCBwYXJzZUludChiW2ldKSl7DQogICAgICAgICAgcmV0dXJuIDE7IA0KICAgICAgfQ0KICAgIH0NCiAgfSk7ICAgIA0KICByZXR1cm4gcGFyc2VJbnQobnVtQXJyLmpvaW4oJycpKTsNCn0NCg0KY29uc29sZS5sb2coYExhcmdlc3QgTnVtYmVyOiAke2xhcmdlc3ROdW1iZXIoWzUwLCAyLCAxLCA5LCA1XSl9YCk7IC8vIDk1NTAyMSAtIFBBU1MNCmNvbnNvbGUubG9nKGBMYXJnZXN0IE51bWJlcjogJHtsYXJnZXN0TnVtYmVyKFs1MCwgNSwgNTZdKX1gKTsgLy8gNTY1NTAgLSBQQVNTDQpjb25zb2xlLmxvZyhgTGFyZ2VzdCBOdW1iZXI6ICR7bGFyZ2VzdE51bWJlcihbNDIwLCA0MiwgNDIzXSl9YCk7IC8vIDQyMzQyNDIwIC0gRkFJTCAoc2hvdWxkIGJlIDQyNDIzNDIwKQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const largestNumber = (numArr) => {
 numArr.sort((a, b) => {
    if(a == b){
      return 0;
    }       
    a = a.toString().split('');
    b = b.toString().split('');     
    const maxLength = a.length > b.length ? a.length : b.length;        
    for(let i = 0; i < maxLength; i++){
      if(!a[i]){
        a[i] = a[i-1];
      }
      if(!b[i]){
        b[i] = b[i-1];
      }
      if(parseInt(a[i]) > parseInt(b[i])){
          return -1;
      }else if(parseInt(a[i]) < parseInt(b[i])){
          return 1; 
      }
    }
  });    
  return parseInt(numArr.join(''));
}

console.log(`Largest Number: ${largestNumber([50, 2, 1, 9, 5])}`); // 955021 - PASS
console.log(`Largest Number: ${largestNumber([50, 5, 56])}`); // 56550 - PASS
console.log(`Largest Number: ${largestNumber([420, 42, 423])}`); // 42342420 - FAIL (should be 42423420)
node v10.16.0