count.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createCount = void 0;
  6. var _factory = require("../../utils/factory.js");
  7. var name = 'count';
  8. var dependencies = ['typed', 'size', 'prod'];
  9. var createCount = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
  10. var typed = _ref.typed,
  11. size = _ref.size,
  12. prod = _ref.prod;
  13. /**
  14. * Count the number of elements of a matrix, array or string.
  15. *
  16. * Syntax:
  17. *
  18. * math.count(x)
  19. *
  20. * Examples:
  21. *
  22. * math.count('hello world') // returns 11
  23. * const A = [[1, 2, 3], [4, 5, 6]]
  24. * math.count(A) // returns 6
  25. * math.count(math.range(1,6)) // returns 5
  26. *
  27. * See also:
  28. *
  29. * size
  30. *
  31. * @param {string | Array | Matrix} x A matrix or string
  32. * @return {number} An integer with the elements in `x`.
  33. */
  34. return typed(name, {
  35. string: function string(x) {
  36. return x.length;
  37. },
  38. 'Matrix | Array': function MatrixArray(x) {
  39. return prod(size(x));
  40. }
  41. });
  42. });
  43. exports.createCount = createCount;