JS easy solution with hashmap
\nvar sortString = function(s) {\n    const hashmap = {};\n    let output = \'\';\n    \n    for (let i = 0; i < s.length; i++) {\n        const code = s.charCo
```\nvar sortString = function(s) {\n    const hashmap = {};\n    let output = \'\';\n    \n    for (let i = 0; i < s.length; i++) {\n        const code = s.charCodeAt(i);\n        if (!hashmap[code]) {\n            hashmap[code] = 1;\n        } else {\n            hashmap[code]++;\n        }\n    }\n    const temp = Object.entries(hashmap);\n    let cursor = 0;\n    let direction = 1;\n\n    while (output.length < s.length && temp.length) {\n        output += String.fromCharCode(temp[cursor][0]);\n        if (temp[cursor][1] > 1) {\n            temp[cursor][1]--;\n        } else {\n            temp.splice(cursor, 1);\n            cursor = cursor + (direction === 1 ? -1 : 0);\n        }\n        cursor += direction;\n        if (cursor === -1 || cursor === temp.length) {\n            direction = -direction;\n            cursor += direction;\n        }\n    }\n\n    return output;\n};\n```
['JavaScript']