Custom Sort String LeetCode solution in JavaScript

1
var customSortString = function (order, s) {
2
const hm = new Map();
3
for (let c of s) {
4
if (!hm.has(c)) hm.set(c, 0);
5
hm.set(c, hm.get(c) + 1);
6
}
7

8
let op = "";
9
for (let c of order) {
10
if (hm.has(c)) {
11
op += "".padStart(hm.get(c), c);
12
hm.delete(c);
13
}
14
}
15
for (let [c, occ] of hm) {
16
op += "".padStart(hm.get(c), c);
17
hm.delete(c);
18
}
19
return op;
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0