Possible bad test in Js exercise Bird Watcher

i started doing the Javascript track and I think I encountered a bad test in the Bird Watcher exercise:
Test 9 says:

const birdsPerDay = [2, 0, 1, 4, 1, 3, 0];
expect(Object.is(fixBirdCountLog(birdsPerDay), birdsPerDay)).toBe(true);

which I believe it will always fail.

According to MDN documentation, Object.is(obj1, obj2) returns true if obj1 and obj2 are the same object, that is, both values reference the same object in memory;
In fact, one can check

let arr = [];
console.log(Object.is(arr,arr)); // true
console.log(Object.is([],arr)); // false
console.log(Object.is([],[])); // false

let  newArr = ['a'];
console.log(Object.is(newArr ,newArr )); // true
console.log(Object.is(['a'],newArr )); // false
console.log(Object.is(['a'],['a'])); // false

Considering that in the test birdsPerDay is a constant (immutable object), the test will fail if one creates a function that

  • modifies the input array
  • creates a new array from the input

Test 9 checks that the output is an array (which I think is redundant considering what Test 10 and Test 11 do) so I would suggest to use the method Array.isArray(value)

const birdsPerDay = [2, 0, 1, 4, 1, 3, 0];

I have tried the following but they all fail Test 9 and pass Test 10 and Test 11:

export function fixBirdCountLog(birdsPerDay) {
  // I assume it fails since it can't modify a constant
  return birdsPerDay.map((num,ind)=>(ind%2==0)?num+1:num);
export function fixBirdCountLog(birdsPerDay) {
  let newArr = [];  // create a new array to return since the input is a constant
  birdsPerDay.forEach((num,ind)=>(ind%2==0) ? newArr.push(num+1):newArr.push(num));
  return newArr;
export function fixBirdCountLog(birdsPerDay) {
  let newArr = []; // create a new array to return since the input is a constant
  for(let ind=0; ind<birdsPerDay.length; ind++){
    if (ind%2==0) newArr.push(birdsPerDay[ind]+1);
    else newArr.push(birdsPerDay[ind]);
  return newArr;

Being constant is a property of variables, but immutability is a property of values. They are not the same.

A constant variable is guaranteed to always point to the same object, but it is not guaranteed that that object will not change. In this case, birdPerDay refers to an array that is expected to mutate.

It will fail when the input array is replaced (which shouldn’t happen, due to const), but not when it is mutated.

Additional answer on top of the feedback from Matthijs here: Possible bad test in Bird Watcher · Issue #6677 · exercism/exercism · GitHub

thank you again for the help, apparently i forgot the definitions :sweat_smile: