I'll also add some checks to make sure the array parameter is actually an array and that it has at least one value
// make sure the array passed in is actually an array
if (!Array.isArray(array)) {
return "Array isn't an array."
}
// make sure we got something to work with in that array
if (array.length === 0) {
return 'Array is empty.'
}
Thanks for doing this, I've been intimidated to try this anywhere else.
From this Stack Overflow question
The function will count how many times an item occurs in an array, even in arrays within the array.
Sample usage and output:
I'll also add some checks to make sure the array parameter is actually an array and that it has at least one value
Let me know if this is acceptable.
Thanks!