1370 | Multiline JavaScript Solution
Typically I\'m offering a "regex solution" or "recursive solution" or "1-line solution", and often a combination of those, but I think this is a pretty good sol
Typically I\'m offering a "regex solution" or "recursive solution" or "1-line solution", and often a combination of those, but I think this is a pretty good solution with regards to runtime.\n\n> Runtime: **64 ms**, faster than *92.70%* of JavaScript online submissions\n> Memory Usage: **37.4 MB**, less than *100.00%* of JavaScript online submissions\n\n```javascript\nconst sortString = s => {\n  const cnts = new Array(26).fill(0);\n  for (let i = 0; i < s.length; i++) cnts[s.charCodeAt(i) - 97]++;\n  const res = new Array(Math.max(...cnts)).fill(\'\');\n  for (let i = 0; i < 26; i++)\n    for (let j = 0; j < cnts[i]; j++)\n      if (0 === j % 2) res[j] += String.fromCharCode(i + 97);\n      else res[j] = String.fromCharCode(i + 97) + res[j];\n  return res.join(\'\');\n};\n```
['JavaScript']