All files / lib/rules get-value-by-rules.js

100% Statements 11/11
100% Branches 6/6
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 225x 5x     39x 4x         35x 38x 38x 24x       11x     5x  
const executeRule = require('./execute-rule');
const executeRuleDefault = require('./execute-rule-default');
 
function getValueByRules(input, rules, values) {
  if (input === undefined || values.length === 0) {
    return;
  }
  let result;
  // for loop for efficiency's sake here,
  // need custom early return
  for (let i = 0; i < rules.length; i += 1) {
    result = executeRule(input, rules[i], values);
    if (result !== undefined) {
      return result;
    }
  }
  // default rule is always processed last.
  return executeRuleDefault(values);
}
 
module.exports = getValueByRules;