Count occurrences

Given a sorted array arr[] and an integer target, find the number of occurrences of target in given array.

Hint

Start at the beginning of the list. Check each item in the list. If the current item matches the "target" value, add 1 to the count.

# Python implementation
ls = [1, 2, 3, 4, 3, 3, 3, 8, 9]
target = 3
count = 0

for item in ls:
  if item == target:
    count += 1

print(count)
// Javascript implementation
const list = [1, 2, 3, 4, 3, 3, 3, 8, 9];
const target = 3;

let output = 0;

for (let item of list) {
  if (item == target) {
    output++;
  }
}

console.log(output);