```
var plusOne = function(digits) {
var residue = 1,
pointer = digits.length - 1;
while(pointer >= 0){
if(residue === 1){
if(digits[pointer] === 9){
digits[pointer] = 0;
residue = 1;
}else{
digits[pointer] += 1;
residue = 0;
}
}
pointer--;
}
if(residue === 1)
digits.unshift(1);
return digits;
};
```