https://leetcode.com/problems/sum-of-unique-elements/



Runtime: 75 ms, faster than 70.00% of TypeScript online submissions for Sum of Unique Elements.

Memory Usage: 45.2 MB, less than 16.00% of TypeScript online submissions for Sum of Unique Elements.



```typescript
function sumOfUnique(nums: number[]): number {
    /*
    //8:01
    let newNums = []
    let shouldSubtract = 0
    for (const num of nums) {
        if (!newNums.includes(num)) {
            newNums.push(num)
        } else {
            shouldSubtract += num
        }
    }
    return newNums.reduce((a,b) => a+b) - shouldSubtract
    //8:02
    //debug until 8:05
    */
    
    //8:08
    let map = new Map();
    for (const num of nums) {
        if (map.has(num)) {
            map.set(num, map.get(num) + 1)
        } else {
            map.set(num, 1)
        }
    }
    let sum = 0
    for (const [key, value] of map.entries()) {
        if (value == 1) {
            sum += key
        }
    }
    return sum
    //8:11
};
```
