---
# System prepended metadata

title: RAHUL KHATRI

---

RAHUL KHATRI
https://drive.google.com/file/d/1_jA8W0d_uSRBjdGafVdF1l9iv1GFWkX_/view

 - too slow
 - got a headache in explaining him such silly qns
 - not satisfied with solutions & performance
 - didnt solve 2nd qn completely even after 35+ mins

1) add digits
```
/**
 * @param {number} num
 * @return {number}
 */
var addDigits = function(num) {
    // 38 -> "38"
    // ["3","8"]

    // 11

    // []

    let individualDigit = num.toString().split("")

    let sum = individualDigit.reduce((initial, current)=>initial+= +current,0)

    if(sum >= 10){
        return addDigits(sum)
    }else{
        return sum
    }

};
```

2) plus one
```
/**
 * @param {number[]} digits
 * @return {number[]}
 */
var plusOne = function(digits) {
    let lastDigit = digits[digits.length-1]

    const newEntery  = lastDigit+1

    if(newEntery==10){
        let secLast = digits[digits.length-2]
        if(!secLast){
            return [1,0]
        }
        digits[digits.length-2] = secLast + 1
        digits[digits.length-1] = 0
    }else{
        digits[digits.length-1] = newEntery
    }

    return digits
};
```

