MCPcopy
hub / github.com/CacheControl/json-rules-engine / prioritizeConditions

Method prioritizeConditions

src/rule.js:171–189  ·  view source on GitHub ↗

* Priorizes an array of conditions based on "priority" * When no explicit priority is provided on the condition itself, the condition's priority is determine by its fact * @param {Condition[]} conditions * @return {Condition[][]} prioritized two-dimensional array of conditions * Ea

(conditions)

Source from the content-addressed store, hash-verified

169 * all conditions with that priority.
170 */
171 prioritizeConditions (conditions) {
172 const factSets = conditions.reduce((sets, condition) => {
173 // if a priority has been set on this specific condition, honor that first
174 // otherwise, use the fact's priority
175 let priority = condition.priority
176 if (!priority) {
177 const fact = this.engine.getFact(condition.fact)
178 priority = (fact && fact.priority) || 1
179 }
180 if (!sets[priority]) sets[priority] = []
181 sets[priority].push(condition)
182 return sets
183 }, {})
184 return Object.keys(factSets)
185 .sort((a, b) => {
186 return Number(a) > Number(b) ? -1 : 1 // order highest priority -> lowest
187 })
188 .map((priority) => factSets[priority])
189 }
190
191 /**
192 * Evaluates the rule, starting with the root boolean operator and recursing down

Callers 2

prioritizeAndRunMethod · 0.95
rule.test.jsFile · 0.80

Calls 1

getFactMethod · 0.80

Tested by

no test coverage detected