Navigation Menu

Skip to content

Commit

Permalink
Separate methods for two- and three-word phrases
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryb committed Jul 15, 2009
1 parent 727fffe commit d5ab509
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions 1.rb
Expand Up @@ -8,22 +8,28 @@ module StringExtensions
def phrases(number)
words = split
all_strings = words
all_strings += double_triple_words(words)
all_strings += double_words(words)
all_strings += triple_words(words)
all_strings[0, number].map {|s| "'#{s}'"}.join(', ')
end

private

def double_triple_words(strings)
def double_words(strings)
all_strings = []
num_words = strings.size

# Extracting double-word phrases
(0...num_words - 1).each do |i|
all_strings << "#{strings[i]} #{strings[i + 1]}"
end
return all_strings
end

def triple_words(strings)
all_strings = []
num_words = strings.size

# Extracting triple-word phrases
(0...num_words - 2).each do |i|
all_strings << "#{strings[i]} #{strings[i + 1]} #{strings[i + 2]}"
end
Expand Down

0 comments on commit d5ab509

Please sign in to comment.