Permalink
Browse files

minor fixes to matching

  • Loading branch information...
1 parent 2b63a0a commit f2231fe5c343e15546f4138cbcd96cfa747f3dcb @mental committed Jan 4, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/Match.coffee
View
@@ -9,7 +9,7 @@ empty_func = ->
is_array = (value) ->
return true if value instanceof Array
- if value and typeof(value) is "object"
+ if typeof(value) is "object"
# fallback necessary for arrays passed to workers (in Chrome)
try
empty_func.apply(this, value)
@@ -21,20 +21,22 @@ is_array = (value) ->
match = (pattern, value) ->
if typeof(pattern) is "object"
- if is_array(pattern)
+ if pattern is null
+ value is null
+ else if is_array(pattern)
return false unless is_array(value)
pattern_length = pattern.length
return false unless value.length is pattern_length
for i in [0...pattern_length]
matched = match(pattern[i], value[i])
return false unless matched
- if pattern is null
- value is null
+ true
else
return null if typeof(value) is not "object"
for name of pattern
matched = match(pattern[name], value[name])
return false unless matched
+ true
else if pattern is ANY
# match anything
true

0 comments on commit f2231fe

Please sign in to comment.