You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Counts the frequency of a certain item occuring in the array.
It may be extended to allow the item to be an array, such that it returns an array of counts.
Here is a possible implementation of the simple version with a single item:
/// @function array_count(array, elt)
/// @param {array} array Input array
/// @param {any} elt The element to count
/// @return frequency
function array_count(_array, _elt)
{
if is_array(_array)
{
var count = 0;
for(var i = 0; i<array_length(_array); i++)
{
if is_array(_array[i])
{
count += array_count(_array[i], _elt);
}
else if (_array[i] == _elt)
{
count += 1;
}
}
return count;
}
else
{
return 0;
}
}
The text was updated successfully, but these errors were encountered:
Counts the frequency of a certain item occuring in the array.
It may be extended to allow the item to be an array, such that it returns an array of counts.
Here is a possible implementation of the simple version with a single item:
The text was updated successfully, but these errors were encountered: