Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ability to create filter function with rules object

  • Loading branch information...
commit 11bc74d6448ba4c6f5e721fd9fb5cead78372c6a 1 parent 892e22c
@kossnocorp authored
Showing with 19 additions and 15 deletions.
  1. +19 −15 src/gtl.coffee
View
34 src/gtl.coffee
@@ -97,32 +97,36 @@ filter = (array, comparator, rule, iterator) ->
result
###
- Public: filter function
+ Private: create filter function
###
-gtl.filter = (array, rules, iterator) ->
- result = clone(array)
+createFilter = (rulesObj) ->
+ (array, rules, iterator) ->
+ result = clone(array)
- unless iterator
- iterator = []
+ unless iterator
+ iterator = []
- if rules.or or rules.in
- iterator.push(rule: 'or', iterator: rules.or || rules.in)
+ if rules.or or rules.in
+ iterator.push(rule: 'or', iterator: rules.or || rules.in)
- if rules.and
- iterator.push(rule: 'and', iterator: rules.and)
+ if rules.and
+ iterator.push(rule: 'and', iterator: rules.and)
- if iterator.length == 0
- iterator = (elm) -> elm
+ if iterator.length == 0
+ iterator = (elm) -> elm
- for name, rule of rules
- if ['or', 'in', 'and'].indexOf(name) == -1
- result = filter(result, gtl.rules[name], rule, iterator)
+ for name, rule of rules
+ if ['or', 'in', 'and'].indexOf(name) == -1
+ result = filter(result, rulesObj[name], rule, iterator)
- result
+ result
# Define rules object
gtl.rules = {}
+# Define filter function
+gtl.filter = createFilter(gtl.rules)
+
###
Public: greater than comparator
###
Please sign in to comment.
Something went wrong with that request. Please try again.