JavaScript Solution
\nvar sortString = function(s) {\n    const n = s.length;\n    const count = new Array(26).fill(0);\n    \n    for (const char of s) {\n        const index = ch
```\nvar sortString = function(s) {\n    const n = s.length;\n    const count = new Array(26).fill(0);\n    \n    for (const char of s) {\n        const index = char.charCodeAt(0) - 97;\n        count[index]++;\n    }\n    \n    let res = "";\n    \n    while (res.length < n) {\n        for (let j = 0; j < 26 && res.length < n; j++) {\n            if (count[j] > 0) {\n                \n                const char = String.fromCharCode(j + 97);\n                res += char;\n                count[j]--;\n            }\n        }\n        \n        if (res.length === n) return res;\n        \n        for (let k = 25; k >= 0 && res.length < n; k--) {\n            if (count[k] > 0) {\n                \n                const char = String.fromCharCode(k + 97);\n                res += char;\n                count[k]--;\n            }\n        }\n        \n        if (res.length === n) return res;\n    }\n};\n```
['JavaScript']