Advertisement
brewersfan1976

array_maximal_adjcent_difference.rb

Mar 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.35 KB | None | 0 0
  1. def arrayMaximalAdjacentDifference(inputArray)
  2.     x = 0
  3.     difference = 0
  4.    
  5.     while (x < inputArray.length - 1)
  6.           if (inputArray[x] - inputArray[x + 1]).abs > difference then
  7.              difference = (inputArray[x] - inputArray[x + 1]).abs
  8.           end
  9.              
  10.           x = x + 1
  11.     end
  12.        
  13.     return difference
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement