Stuck in javascript list-ops

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

The test expects you to return the custom List object, not an Array. Note the test is checking the the .values property on the returned object.

I don’t get it. I can return this and I get undefined.
I can set it equal to a new array called newList and return new List(newList). I get undefined.

I don’t understand this at all.

The tests expect List.values to be defined. How do you define that property?

Please share your whole code. I’m particularly interested to see your constructor.

I got it. I hadn’t looked at the constructor and I had wondered about values but I thought it was some syntax that belonged to the test. I hadn’t seen that it was actually a clue.

Thank you very much.

I got it. Thanks for the clue. I had not looked at that constructor.

Thank you very much.