brewersfan1976

alpha_numeric_less.rb

Oct 14th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.77 KB | None | 0 0
  1. def alphanumericLess(s1, s2)
  2.     x = 0
  3.     string1 = ""
  4.     string2 = ""
  5.    
  6.     while (x < s1.length)
  7.           if s1[x] != '0' then
  8.              string1 = string1 + s1[x]
  9.           end
  10.              
  11.           x = x + 1
  12.     end
  13.        
  14.     x = 0
  15.        
  16.     while (x < s2.length)
  17.           if s2[x] != '0' then
  18.              string2 = string2 + s2[x]
  19.           end
  20.              
  21.           x = x + 1
  22.     end
  23.        
  24.     if string1.length < string2.length then
  25.        return true
  26.     end
  27.        
  28.     if string1 == string2 then
  29.        if s1.length > s2.length then
  30.           return true
  31.        else
  32.           return false
  33.        end
  34.     end
  35.        
  36.     if string1 < string2 then
  37.        return true
  38.     else
  39.        return false
  40.     end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment