Problem 20
Count value in array Recursion Challenge
Given an array and a target value, return the number of times the target appears in the array. Comparisons use strict equality.
Function Signature
countOccurrence(array, value)
Parameters
array— an array of values (numbers, strings,undefined,null, booleans, etc.).value— the target value to count.
Output
Return a number representing how many times value appears in the array.
Constraints
- The function must use recursion.
- The function should accept exactly two arguments.
Examples
countOccurrence([2, 7, 4, 4, 1, 4], 4) → 3
countOccurrence([2, 'banana', 4, 4, 1, 'banana'], 'banana') → 2
countOccurrence([undefined, 7, undefined], undefined) → 2
countOccurrence(['', null, 0, '0', false], 0) → 1
countOccurrence(['', null, 0, 'false', false], false) → 1