https://leetcode.com/problems/find-original-array-from-doubled-array/



Runtime: 8035 ms, faster than 8.70% of TypeScript online submissions for Find Original Array From Doubled Array.

Memory Usage: 66.7 MB, less than 91.30% of TypeScript online submissions for Find Original Array From Doubled Array.



```typescript
function findOriginalArray(changed: number[]): number[] {
    //8:06
    const length = changed.length
    if ((length % 2) != 0) {
        return []
    }
    
    changed.sort((a,b) => a-b)
    let loopTime = length / 2
    
    let result = []
    
    while (loopTime > 0) {
        const value = changed.shift()
        const double_value = value * 2
        
        if (changed.includes(double_value)) {
            result.push(value)  
            
            const index = changed.indexOf(double_value);
            if (index !== -1) {
              changed.splice(index, 1);
            }
        } else {
            return []
        }
        
        loopTime -= 1
    }
    
    //console.log(changed, result)
    if (changed.length > 0) {
        return []
    } else {
        return result
    }
    //8:15
    //debug until 8:19
};
```
