Permalink
Browse files

No need to calculate single words when we already have them

  • Loading branch information...
1 parent e6cba04 commit 04b2a467e08862d4ffc58688492c41a3f19673d1 @kerryb committed Jul 14, 2009
Showing with 3 additions and 9 deletions.
  1. +3 −9 1.rb
View
12 1.rb
@@ -7,25 +7,19 @@
module StringExtensions
def phrases(number)
words = split
- all_strings = single_double_triple_words(words)
+ all_strings = words
+ all_strings += double_triple_words(words)
all_strings[0, number].map {|s| "'#{s}'"}.join(', ')
end
private
- def single_double_triple_words(strings)
+ def double_triple_words(strings)
all_strings = []
num_words = strings.size
return all_strings unless has_enough_words(num_words)
- # Extracting single words. Total size of words == num_words
-
- # Extracting single-word phrases.
- (0...num_words).each do |i|
- all_strings << strings[i]
- end
-
# Extracting double-word phrases
(0...num_words - 1).each do |i|
all_strings << "#{strings[i]} #{strings[i + 1]}"

0 comments on commit 04b2a46

Please sign in to comment.