Last active
          March 2, 2017 06:12 
        
      - 
      
- 
        Save Underdoge/62bcb0e214591418846d7ec964bdb039 to your computer and use it in GitHub Desktop. 
    arrayChange
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function arrayChange(inputArray) { | |
| var moves=0; | |
| for(var i=0;i+1<inputArray.length;i++){ | |
| if(inputArray[i]-inputArray[i+1]>=0) | |
| if(inputArray[i]-inputArray[i+1]==0){ | |
| moves++; | |
| inputArray[i+1]++; | |
| }else{ | |
| moves+=inputArray[i]-inputArray[i+1]+1; | |
| inputArray[i+1]+=inputArray[i]-inputArray[i+1]+1; | |
| } | |
| } | |
| return moves; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment