Skip to content

Instantly share code, notes, and snippets.

@ms314006
Created March 10, 2020 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms314006/fd7a78db48acc56688741ae369b7c330 to your computer and use it in GitHub Desktop.
Save ms314006/fd7a78db48acc56688741ae369b7c330 to your computer and use it in GitHub Desktop.
var plusOne = function(digits) {
for(let i = digits.length - 1; i >= 0; i--) {
let lastDigit = digits[i];
if (lastDigit < 9) {
digits[i] += 1;
return digits;
}
digits[i] = 0;
}
return [1, ...digits]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment