fork download
  1. function getNumber(s) {
  2. for (const char of s) {
  3. let n = parseInt(char);
  4. if (! isNaN(n)) { // se é número, retorna
  5. return n;
  6. }
  7. }
  8. // estou assumindo que sempre terá um número na string, então aqui não retorno nada
  9. }
  10.  
  11. function order(frase) {
  12. if (frase.length == 0){
  13. return '';
  14. }
  15. return frase.split(' ')
  16. .sort((a, b) => getNumber(a) - getNumber(b))
  17. .join(' ');
  18. }
  19.  
  20. console.log(order("4of Fo1r pe6ople g3ood th5e the2"));
  21.  
Success #stdin #stdout 0.04s 19088KB
stdin
Standard input is empty
stdout
Fo1r the2 g3ood 4of th5e pe6ople