_createRelationalOperation.js 578 B

123456789101112131415161718192021
  1. var toNumber = require('./toNumber');
  2. /**
  3. * Creates a function that performs a relational operation on two values.
  4. *
  5. * @private
  6. * @param {Function} operator The function to perform the operation.
  7. * @returns {Function} Returns the new relational operation function.
  8. */
  9. function createRelationalOperation(operator) {
  10. return function(value, other) {
  11. if (!(typeof value == 'string' && typeof other == 'string')) {
  12. value = toNumber(value);
  13. other = toNumber(other);
  14. }
  15. return operator(value, other);
  16. };
  17. }
  18. module.exports = createRelationalOperation;