From e0a9cb92e82f0f2d7d7710df8651069defb5a388 Mon Sep 17 00:00:00 2001 From: Yusin Date: Sat, 9 Mar 2024 18:31:45 +0300 Subject: [PATCH] Finished Task --- yusin888/count_zeros.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 yusin888/count_zeros.js diff --git a/yusin888/count_zeros.js b/yusin888/count_zeros.js new file mode 100644 index 00000000..5eceb5ff --- /dev/null +++ b/yusin888/count_zeros.js @@ -0,0 +1,14 @@ +function countZeros(A) { + let count = 0; // Initialize count of zeros + for (let number of A) { // Loop through each element in the array + if (number === 0) { // Check if the element is zero + count++; // Increment the count if a zero is found + } + } + return count; // Return the total count of zeros +} + +// Example usage +const A = [1, 0, 5, 6, 0, 2]; +const result = countZeros(A); +console.log(result); // Output should be 2