brewersfan1976

timed_reading.rb

Oct 9th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 KB | None | 0 0
  1. def timedReading(maxLength, text)
  2.     words = 0
  3.     array = Array.new
  4.     x = 0
  5.     new_text = ""
  6.    
  7.     while (x < text.length)
  8.           if (text[x] >= 'A' and text[x] <= 'Z') or (text[x] >= 'a' and text[x] <= 'z') or text[x] == ' ' then
  9.              new_text = new_text + text[x]
  10.           end
  11.              
  12.           x = x + 1
  13.     end
  14.        
  15.     array = new_text.split(" ")
  16.     x = 0
  17.        
  18.     while (x < array.length)
  19.           if array[x].length <= maxLength then
  20.              words = words + 1
  21.           end
  22.              
  23.           x = x + 1
  24.     end
  25.        
  26.     return words
  27.    
  28. end
Advertisement
Add Comment
Please, Sign In to add comment