---
# System prepended metadata

title: Pooja Patel

---

Pooja Patel
https://drive.google.com/file/d/1rlIckF21OxJqfzbgg6twLvDPcUKs-JFJ/view

* was low on confidence initially, struggled with 1st question, but finally completed
* was able to change code properly from one approach to another
* implemented 2nd easy question correct and fast
* implemented medium level qn also correctly
* except for 1st qn, was very clear and quick in thinking and logic building
* handson in js looks good
* prev experience seems relevant

1) add digits
```
/**
 * @param {number} num
 * @return {number}
 */
var addDigits = function(num) {
    if(Math.floor(num/10) == 0){
        return num;
    }

    // function addNumberDigits(currentNumber){
    //     if([0,1,2,3,4,5,6,7,8,9].includes(currentNumber)){
    //         return currentNumber;
    //     }

    //     let sum = 0;
    //     while(currentNumber){
    //         sum+= currentNumber%10;
    //         currentNumber = Math.floor(currentNumber/10);
    //     }

    //     return addNumberDigits(sum);
    // }

    // return addNumberDigits(num);

    let currentNumber = num;
    while(![0,1,2,3,4,5,6,7,8,9].includes(currentNumber)){
        let sum = 0;
    while(currentNumber){
        sum+= currentNumber%10;
        currentNumber = Math.floor(currentNumber/10);
    }
        currentNumber = sum;
    }

    return currentNumber;
};
```

2) array transform https://jsfiddle.net/uxajzywL/
```
function transformJSON(input){
    let outputJSON = {};
    for(let i =0; i< input.length; i++){
        const entry = input[i];

        if(!outputJSON[entry.state]){
            outputJSON[entry.state] = {};
        }
        if(!outputJSON[entry.state][entry.city]){
            outputJSON[entry.state][entry.city] = [];
        }
        outputJSON[entry.state][entry.city].push(entry.pincode);
    }

    return outputJSON;
}

console.log(transformJSON(input))
```

3) Flatten Deeply Nested Array
```
/**
 * @param {Array} arr
 * @param {number} depth
 * @return {Array}
 */
var flat = function (arr, n) {
    if(n == 0){
        return arr;
    }

    let currentArray = arr;

    while(n > 0){
    let outputArray = [];
    for(let i = 0; i < currentArray.length; i++){
        if(Array.isArray(currentArray[i])){
            outputArray.push(...currentArray[i]);
        } else{
            outputArray.push(currentArray[i])
        }
    }

    n--;
    currentArray = outputArray;
    }

    return currentArray;
};
```