JS Built-ins
TypeScriptbeginner

Advanced β€” countOccurrences

πŸ“– Usage Example
countOccurrences([1, 2, 2, 3, 3, 3], 3)   // β†’ 3

countOccurrences counts how many times a given value appears in an array.

Advanced: Count Element Occurrences

Challenge: Implement countOccurrences<T>(arr: T[], value: T): number counting how many times value appears.

countOccurrences([1,2,3,2,1,2], 2)  // β†’ 3
πŸ’‘ Hints (1)
  • β€’ Filter by strict equality, then check the length.