I want to generate all possible consecutive word combinations of a particular string, given a minimum length as an arg.
So say I have "hello", the result would be (given a min length of 3): 'hel', 'ell', 'llo', 'hell', 'ello', 'hello'.
One way I've achieve this is via:
def get_all_word_combinations(str, min_length)
chars = str.split('')
all_results = []
(min_length..str.size).each do |x|
chars.each_cons(x) do |r|
all_results << r.join
end
end
return all_results
end
But not sure if this would work with bigger words.