subtract.js 458 B

123456789101112131415
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var NumberAdd = require('./add');
  4. var NumberUnaryMinus = require('./unaryMinus');
  5. // https://262.ecma-international.org/12.0/#sec-numeric-types-number-subtract
  6. module.exports = function NumberSubtract(x, y) {
  7. if (typeof x !== 'number' || typeof y !== 'number') {
  8. throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
  9. }
  10. return NumberAdd(x, NumberUnaryMinus(y));
  11. };