Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 770B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. var arrayify = require('array-ify');
  3. var dotPropGet = require('dot-prop').get;
  4. function compareFunc(prop) {
  5. return function(a, b) {
  6. var ret = 0;
  7. arrayify(prop).some(function(el) {
  8. var x;
  9. var y;
  10. if (typeof el === 'function') {
  11. x = el(a);
  12. y = el(b);
  13. } else if (typeof el === 'string') {
  14. x = dotPropGet(a, el);
  15. y = dotPropGet(b, el);
  16. } else {
  17. x = a;
  18. y = b;
  19. }
  20. if (x === y) {
  21. ret = 0;
  22. return;
  23. }
  24. if (typeof x === 'string' && typeof y === 'string') {
  25. ret = x.localeCompare(y);
  26. return ret !== 0;
  27. }
  28. ret = x < y ? -1 : 1;
  29. return true;
  30. });
  31. return ret;
  32. };
  33. }
  34. module.exports = compareFunc;