Commit 636fd84

mo <mokha@cisco.com>
2017-08-11 16:33:48
sort parts.
1 parent e96dd6f
Changed files (1)
spec
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}]")