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