brewersfan1976

array_consecutive.rb

Feb 25th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.33 KB | None | 0 0
  1. def makeArrayConsecutive2(sequence)
  2.     sequence = sequence.sort
  3.     x = 0
  4.     array_length = sequence.length
  5.     number = 0
  6.     difference = 0
  7.    
  8.     while (x < array_length - 1)
  9.         difference = (sequence[x + 1] - sequence[x]) - 1
  10.         number = number + difference
  11.         x = x + 1
  12.     end
  13.    
  14.     return number
  15. end
Advertisement
Add Comment
Please, Sign In to add comment