glennj
July 23, 2025, 7:37pm
1
Task 3 says (emphasis mine):
[…] write a function fixBirdCountLog that takes an array of birds counted per day as an argument. It should correct the counting mistake and return the modified array .
But the tests expect the input “array” to be modified in-place. javascript/exercises/concept/bird-watcher/bird-watcher.spec.js at 6b1bb1269d211e9f75e4f34b89e92b00382ebe34 · exercism/javascript · GitHub
I coded this:
export function fixBirdCountLog(birdsPerDay) {
const fixed = new Array(birdsPerDay.length);
for (let i = 0; i < birdsPerDay.length; i++) {
fixed[i] = birdsPerDay[i] + (i % 2 == 0 ? 1 : 0);
}
return fixed;
}
But the tests need this:
export function fixBirdCountLog(birdsPerDay) {
for (let i = 0; i < birdsPerDay.length; i+=2) {
birdsPerDay[i]++;
}
return;
}
2 Likes
The stub has a comment indicating nothing should be returned, which doesn’t contradict the test suite. It seems reasonable to me to perhaps update the docs. Would saying something like modify the array in-place be more clear than return the modified array?
*/
export function birdsInWeek(birdsPerDay, week) {
throw new Error('Remove this line and implement the function');
}
/**
* 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) {
throw new Error('Remove this line and implement the function');
}
IsaacG
July 23, 2025, 7:57pm
3
Maybe just modify the array? Coupled with no return value, that ought to be clear and simple.
2 Likes
I like modify the array in-place but the simpler version (modify the array) is probably better and less confusing.
PRs welcome.
1 Like