brewersfan1976

array_previous_less.rb

Oct 15th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.53 KB | None | 0 0
  1. def arrayPreviousLess(items)
  2.     output = Array.new
  3.     output[0] = -1
  4.     x = 1
  5.     y = 1
  6.    
  7.     while (x < items.length)
  8.           z = x - 1
  9.        
  10.           while (z >= 0)
  11.                 if items[z] < items[x] then
  12.                    output[y] = items[z]
  13.                    break
  14.                 else
  15.                    output[y] = -1
  16.                 end
  17.                    
  18.                 z = z - 1
  19.           end
  20.              
  21.           x = x + 1
  22.           y = y + 1
  23.     end
  24.        
  25.     return output
  26. end
Advertisement
Add Comment
Please, Sign In to add comment