Refactor code by suggestion to use RegExp and add tests coverage

This commit is contained in:
Julius Pabrinkis
2017-04-21 12:10:40 +01:00
committed by Rob Harrington
parent 7a07e8fa16
commit a1ffc869f3
2 changed files with 56 additions and 4 deletions

View File

@@ -10,7 +10,5 @@ Darkswarm.factory "Matcher", ->
# Return true if text occurs at the beginning of any word present in an array of strings
matchBeginning: (properties, text) ->
text = text.trim()
properties.some (prop) ->
prop ||= ""
prop.split(' ').some (word) ->
word.toLowerCase().indexOf(text.toLowerCase()) == 0
regexp = new RegExp("(?:^|[\\s-])#{text}", "i")
properties.some (prop) -> (prop || "").search(regexp) >= 0