You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
397 B

4 years ago
  1. function ruleSorter(s1, s2) {
  2. return s1[1] > s2[1] ? 1 : -1;
  3. }
  4. function tidyRuleDuplicates(rules) {
  5. var list = [];
  6. var repeated = [];
  7. for (var i = 0, l = rules.length; i < l; i++) {
  8. var rule = rules[i];
  9. if (repeated.indexOf(rule[1]) == -1) {
  10. repeated.push(rule[1]);
  11. list.push(rule);
  12. }
  13. }
  14. return list.sort(ruleSorter);
  15. }
  16. module.exports = tidyRuleDuplicates;