Hi,
I’m stuck in the first task and I notice the same kind of feedback popping up in task 2. I suspect I don’t really understand what I’m asked to to. There is one test I’m just not passing in task one and for the life of me, I can’t say why.
These are the instructions:
append (given two lists, add all items in the second list to the end of the first list);
This is the test:
test('non-empty lists', () => {
const list1 = new List([1, 2]);
const list2 = new List([2, 3, 4, 5]);
expect(list1.append(list2).values).toEqual([1, 2, 2, 3, 4, 5]);
});
Here’s the code: I’m passing the first three conditions with no problem but I’m just not able to pass the last one.
append(list2) {
if(this.list != undefined && list2.list === undefined) {
return this;
}
else if(this.list === undefined && list2.list === undefined) {
return new List();
}
else if(this.list === undefined && list2.list != undefined) {
return list2;
}
else if(this.list != undefined && list2.list != undefined) {
this.list.push(...list2.list);
return this.list; // logs as [1, 2, 2, 3, 4, 5]
}
}
The problem lies in the last conditional.
And this is what I get as result
Expected: [1, 2, 2, 3, 4, 5]
Received: [Function values]
Function values ? I don’t get it. When I log this.list I can see the array I’m supposed to return and I’m returning this.list. I’ve also tried with a for-loop and push(). Nothing works. What is that I’m not getting ?
I’ve been at it for days now. Any help is welcome.
Thanks and greetings,
Karin