src/util/Util.js
/**
  * Count the number of elements in the input array that match the given value.
  *
  * <p> Note: count is able to handle NaN, null, as well as any value convertible to a JSON string.</p>
  *
  * @name module:util.count
  * @function
  * @public
  * @param {array} input the input array
  * @param {Number|string|object|null} value the matching value
  * @returns the number of matching elements
  */
Count the number of elements in the input array that match the given value.
 Note: count is able to handle NaN, null, as well as any value convertible to a JSON string.


Count the number of elements in the input array that match the given value . Note : count is able to handle NaN null as well as any value convertible to a JSON string .
function count(input, value)
{
	const response = {
		origin: "util.count",
		context: "when counting how many elements in the input array match the given value",
	};
	try
	{
		if (!Array.isArray(input))
		{
			throw "the input argument should be an array";
		}
		const match = _match(value);
		let nbMatches = 0;
		input.forEach((element) =>
		{
			if (match(element))
			{
				++nbMatches;
			}
		});
		return nbMatches;
	}
	catch (error)
	{
		throw { ...response, error };
	}
}
function count ( input , value ) { const response = { origin : "util.count" , context : "when counting how many elements in the input array match the given value" , } ; try { if ( ! Array . isArray ( input ) ) { throw "the input argument should be an array" ; } const match = _match ( value ) ; let nbMatches = 0 ; input . forEach ( ( element ) => { if ( match ( element ) ) { ++ nbMatches ; } } ) ; return nbMatches ; } catch ( error ) { throw { ... response , error } ; } }
Count the number of elements in the input array that match the given value.
Count the number of elements in the input array that match the given value .