https://leetcode.com/problems/rearrange-characters-to-make-target-string


Runtime: 108 ms, faster than 100.00% of TypeScript online submissions for Rearrange Characters to Make Target String.

Memory Usage: 45.3 MB, less than 100.00% of TypeScript online submissions for Rearrange Characters to Make Target String.



```typescript
function rearrangeCharacters(s: string, target: string): number {
    //8:04
    const theMap = new Map()
    for (const char of s.split('')) {
        if (theMap.has(char)) {
            theMap.set(char, theMap.get(char) + 1)
        } else {
            theMap.set(char, 1)
        }
    }
    let counting = 0
    let goOn = true
    while (goOn) {
        let ok = true 
        for (const char of target.split('')) {
            if (theMap.has(char)) {
                if (theMap.get(char) > 0) {
                    //pass
                    theMap.set(char, theMap.get(char) - 1)
                } else {
                    ok = false
                    goOn = false
                    break
                }
            } else {
                ok = false
                goOn = false
                break
            }
        }
        if (ok == true) {
            counting += 1
        }
    }
    return counting
    //8:10
};
```
