@nstanovic When confronted with an unclear test failure it often helps to read the code of the test in question.
If you are working locally you should have the bird-watcher.spec.js file, and otherwise you’d have to look it up in the track repo. Sieben has linked to it above.
Do you understand this code? If not, which parts do you not understand?
Hello and thank you very much for the tips and advice. I misunderstood what the test wanted as a passing condition. I am confused at how I will modify the values of a const array. I assumed that const arrays cannot have their values changed. If this is not the case, I will do more research. My code did have a return statement but I forgot to post it as part of the code previously. Tomorrow, my goal will be to figure out a solution. Thanks again very much!
export function fixBirdCountLog(birdsPerDay) {
const correctedBirdCount = [];
for (let i = 0; i < birdsPerDay.length; i += 2) {
correctedBirdCount.push(birdsPerDay[i] + 1);
if (i + 1 < birdsPerDay.length) {
correctedBirdCount.push(birdsPerDay[i + 1]);
}
}
export function fixBirdCountLog(birdsPerDay) {
const correctedBirdCount = [];
for (let i = 0; i < birdsPerDay.length; i += 2) {
correctedBirdCount.push(birdsPerDay[i] + 1);
if (i + 1 < birdsPerDay.length) {
correctedBirdCount.push(birdsPerDay[i + 1]);
}
}
return correctedBirdCount;
}
Did you look at the test code? Do you understand what it is testing? Do you understand why your code fails that test requirement?
test('does not create a new array', () => {
const birdsPerDay = [2, 0, 1, 4, 1, 3, 0];
// This checks that the same object that was passed in is returned.
// https://jestjs.io/docs/expect#tobevalue
expect(Object.is(fixBirdCountLog(birdsPerDay), birdsPerDay)).toBe(true);
});
export function fixBirdCountLog(birdsPerDay) {
for (let i = 0; i < birdsPerDay.length; i += 2) {
birdsPerDay[i] = birdsPerDay[i]+1
}
console.log(birdsPerDay)
return birdsPerDay;
}
The const prevents the re-assignment of the initial name you assigned to the array, but it does not prevent changing the contents of the array. You’ll get an error only if you write const x = [1]; x = [2] but not when you write const x = [1]; x[0] = 2