From 5e2e04ffe3f6635fe3a4c53d908a709768036de3 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Thu, 28 Aug 2025 17:21:54 +0000 Subject: [PATCH] [Sync Iteration] javascript/bird-watcher/1 --- .../javascript/bird-watcher/1/bird-watcher.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 solutions/javascript/bird-watcher/1/bird-watcher.js diff --git a/solutions/javascript/bird-watcher/1/bird-watcher.js b/solutions/javascript/bird-watcher/1/bird-watcher.js new file mode 100644 index 0000000..d434110 --- /dev/null +++ b/solutions/javascript/bird-watcher/1/bird-watcher.js @@ -0,0 +1,52 @@ +// @ts-check +// +// The line above enables type checking for this file. Various IDEs interpret +// the @ts-check directive. It will give you helpful autocompletion when +// implementing this exercise. + +/** + * Calculates the total bird count. + * + * @param {number[]} birdsPerDay + * @returns {number} total bird count + */ +export function totalBirdCount(birdsPerDay) { + let total = 0; +for(let i = 0; i < birdsPerDay.length; i++){ + total += birdsPerDay[i]; +} + return total; +} + +/** + * Calculates the total number of birds seen in a specific week. + * + * @param {number[]} birdsPerDay + * @param {number} week + * @returns {number} birds counted in the given week + */ +export function birdsInWeek(birdsPerDay, week) { + const startIndex = (week - 1) * 7; + const endIndex = startIndex + 7 ; + let total = 0; + for ( let i = startIndex; i < endIndex; i++){ + total += birdsPerDay[i] + } + return total; +} + +/** + * Fixes the counting mistake by increasing the bird count + * by one for every second day. + * + * @param {number[]} birdsPerDay + * @returns {void} should not return anything + */ +export function fixBirdCountLog(birdsPerDay) { + + for (let i = 0; i < birdsPerDay.length; i += 2) { + birdsPerDay[i] += 1; + } + + +}