```
var plusOne = function(digits) {
let carry = 1;
var i = digits.length-1;
while(i >= 0 && carry === 1) {
digits[i] = digits[i] + carry;
if(digits[i] === 10) {
digits[i] = 0;
i--;
}else if(digits[i] < 10) {
carry = 0;
}
}
if(carry === 1) {
digits.unshift(1);
}
return digits;
};
```