Commit e96dd6f

mo <mokha@cisco.com>
2017-08-09 22:22:59
first attempt regex matching.
1 parent 8a9b926
Changed files (1)
spec
spec/binary_trees/find_substrings_spec.rb
@@ -35,7 +35,18 @@ DOC
 
 describe "#find_substrings" do
   def find_substrings(words, parts)
-    words
+    regex = /(#{parts.join("|")})/
+    puts regex.inspect
+    words.map do |word|
+      match = word.match(regex)
+      if match
+        max = match.captures.max { |a, b| a.length <=> b.length }
+        puts [word, match.captures, max].inspect
+        word.gsub(max, "[#{max}]")
+      else
+        word
+      end
+    end
   end
 
   [