Given an array arr[] and an integer target, find the number of occurrences of target in the array. The implementation scans every element, so the input does not need to be sorted.
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.
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)
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);