Custom Sort String LeetCode solution in JavaScript
1var customSortString = function (order, s) {2const hm = new Map();3for (let c of s) {4if (!hm.has(c)) hm.set(c, 0);5hm.set(c, hm.get(c) + 1);6}78let op = "";9for (let c of order) {10if (hm.has(c)) {11op += "".padStart(hm.get(c), c);12hm.delete(c);13}14}15for (let [c, occ] of hm) {16op += "".padStart(hm.get(c), c);17hm.delete(c);18}19return op;20};