SHARE
TWEET

Untitled

a guest Jun 16th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function increment ( numbers ) {
  2.  
  3.   let iterator = numbers.length - 1
  4.  
  5.   while ( iterator >= 0 ) {
  6.     let num = numbers[ iterator ]
  7.     num++
  8.  
  9.     if (num > 0 && num <= 9) {    
  10.       numbers[ iterator ] = num
  11.       break
  12.     } else {
  13.       numbers[ iterator ] = 0
  14.       if ( iterator == 0 ) { // For the [ 9, 9, 9 ] case
  15.         numbers.unshift(1)
  16.         break
  17.       }
  18.       iterator--
  19.     }
  20.   }
  21.   return numbers
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top