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; + } + + +}