Count occurrences
TypeScript Loops
loop + counter
Flowchart (ISO 5807)
Source code
function countOccurrences(a: number[], key: number): number {
let count = 0;
for (let i = 0; i < a.length; i++) {
if (a[i] === key) {
count++;
}
}
return count;
}