Reusable Accessible Mapping Platform

API Docs for: 3.0.0
Show:

File: src\js\RAMP\Utils\decorator.js

  1. /* global define */
  2.  
  3. /**
  4. * @module Utils
  5. */
  6.  
  7. /**
  8. * A class containing functions that accepts a function as argument and returns a function.
  9. *
  10. *
  11. * @class Decorator
  12. * @static
  13. */
  14. define([],
  15. function () {
  16. "use strict";
  17. return {
  18. /**
  19. * Given a comparator function that takes two objects and returns an integer (positive integer
  20. * means the first object is greater in sort order than the second object, negative integer
  21. * means the second object is greater in sort order than the first object, zero if both objects
  22. * have the same sort order). Returns a function that takes one object compares it to the given
  23. * target using the given compareFcn and returns the result of the `compareFcn`.
  24. *
  25. * A useful scenario of this function would be if one had a sorting function used to sort an array
  26. * then one wishes to perform binary search on the sorted array.
  27. *
  28. * @method getFindFcn
  29. * @static
  30. * @param {Function} compareFcn
  31. * @param {Object} target
  32. * @return {Function} that takes one object compares it to the given target using the given compareFcn and returns the result of the compareFcn
  33. */
  34. getFindFcn: function (compareFcn, target) {
  35. function findFcn(obj) {
  36. return compareFcn(target, obj);
  37. }
  38.  
  39. return findFcn;
  40. }
  41. };
  42. });