brewersfan1976

truncate_string.rb

Mar 6th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.53 KB | None | 0 0
  1. def truncateString(s)
  2.    
  3.     while (true)
  4.           if s[0].to_i % 3 == 0 then
  5.              s[0] = ""
  6.              
  7.              elsif s[s.length - 1].to_i % 3 == 0 then
  8.                      s[s.length - 1] = ""
  9.              
  10.                elsif (s[0].to_i + s[s.length - 1].to_i) % 3 == 0 then
  11.                           s[0] = ""
  12.                           s[s.length - 1] = ""
  13.           else
  14.              return s
  15.           end
  16.                
  17.           if s == "" then
  18.              return s
  19.           end  
  20.     end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment