---
# System prepended metadata

title: NITIN SANATAN

---

NITIN SANATAN
https://drive.google.com/file/d/1eGhRErKvbaVirHlKuhSDKyyTYImpucJc/view

- reaching 80% close to soln, but not able to complete
- solved only 1 qn, took so much time
- not so clear with thoughts
- js handson also not satisfactory

1) sum of digits until single digit

```
class Solution {
public:
    int getSum (int sum, int num) {
        while(num) {
            sum += (num%10);
            num = (num / 10);
        }

        return sum;
    }
    int addDigits(int num) {
        int rem = 0;
        int sum = 0;
        if (num == 0){
            return 0;
        }

        int res = num;
        while (res/10 != 0){
            res = getSum(sum, res);
        }

        return res;
    }
};
```

2) array transformation https://jsfiddle.net/uxajzywL/
```
const input = [
    { "pincode" : 382225, "state" : "Gujarat", "city" : "Bavala" },
    { "pincode" : 600060, "state" : "Tamil Nadu", "city" : "Chennai" },
    { "pincode" : 600062, "state" : "Tamil Nadu", "city" : "Chennai" },
    { "pincode" : 600095, "state" : "Tamil Nadu", "city" : "Chennai" },
    { "pincode" : 523115, "state" : "Andhra Pradesh", "city" : "Gudlluru" },
    { "pincode" : 382240, "state" : "Gujarat", "city" : "Bavala" },
    { "pincode" : 638403, "state" : "Tamil Nadu", "city" : "Palladam" },
    { "pincode" : 370602, "state" : "Gujarat", "city" : "Dayapar" }
]

const output = {
    'Tamil Nadu': {
        'Chennai': [600060, 600062, 600095], 
        'Palladam': [638403]
    },
    'Gujarat': { 
        'Bavala': [382225, 382240],
        'Dayapar': [370602]
    },
    'Andhra Pradesh': { 
        'Gudlluru': [523115]
    }
}

const final = {};
const o = input.forEach(obj => {
    if (!final.hasOwnProperty(obj['satetate'])){
        = {
            obj.state : {
                obj.city = obj.pincode;
            }
        };
    }
    else {
        if (!final[obj.state].hasOwnProperty(obj.city)){
        final[obj.city] = [obj.pincode];
        }
        else{
            final[obj.city].push(obj.pincode);
        }

    }
})

console.log(final);
```