brewersfan1976

array_previous_less.rb

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