summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mokha@cisco.com>2017-08-11 10:33:48 -0600
committermo <mokha@cisco.com>2017-08-11 10:33:48 -0600
commit636fd84c303ee738ca8a4ea7ace02142a2d0962f (patch)
tree5b24e5d4ead6214e0b280e00d3cd1e9632bcfe5a
parente96dd6f704956291c99ff2495954fb31f07280cc (diff)
sort parts.
-rw-r--r--spec/binary_trees/find_substrings_spec.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/spec/binary_trees/find_substrings_spec.rb b/spec/binary_trees/find_substrings_spec.rb
index 60b7333..a3a1d09 100644
--- a/spec/binary_trees/find_substrings_spec.rb
+++ b/spec/binary_trees/find_substrings_spec.rb
@@ -35,11 +35,11 @@ DOC
describe "#find_substrings" do
def find_substrings(words, parts)
- regex = /(#{parts.join("|")})/
+ regex = /(#{parts.sort { |a, b| b.length <=> a.length }.join("|")})/
+
puts regex.inspect
words.map do |word|
- match = word.match(regex)
- if match
+ if match = word.match(regex)
max = match.captures.max { |a, b| a.length <=> b.length }
puts [word, match.captures, max].inspect
word.gsub(max, "[#{max}]")