Tests of the Elyses Enchantments issue

I’m doing the Elyses Enchantments in javascript exercice and I think something is not consistent between the tests and the instructions. In short it’s about list manipulation, adding things at the end, at the start, slice etc…

It’s a learning exercice so the code is prefilled with lots of comments. these comments specify for each methods to “return” a list with the extra values in it. Problem in nearly all the task test, the last one call the method twice and expect the value to change without using the returned value. So what the tests want is for us to mutate the initial list. I think it’s just fine but unclear and maybe disturbing for developer that are not used to pointers.

Here is a example:

This is the requested method:

 * Insert newCard at the end of the cards array
 * @param {number[]} cards
 * @param {number} newCard
 * @returns {number[]} the cards with the newCard applied
export function insertItemAtTop(cards, newCard) {}

and this is my proposed solution:

export function insertItemAtTop(cards, newCard) {
    return cards.concat([newCard])

Which works for all tests but the last one:

const stack = [1];
insertItemAtTop(stack, 5);
insertItemAtTop(stack, 9);
const expected = [1, 5, 9];

I think the tests of the task should be:

const stack = [1];
const expected = [1, 5, 9];
expect(insertItemAtTop(insertItemAtTop(stack, 5), 9)).toStrictEqual(expected);

which would rely on the return statement of the method and not the mutation of the cards list.

I think this is working for most of the new users because they use the suggested push and pop method which change the cards list inplace but not explaining it can lead to real issues down the learning path.

What do you think ? Am I 100% wrong ?

This unconsistency is repeated for every task.

PS: note that I searched the forum to find the best place to post this (as requested in my last PR) but I’m not sure I posted it in the correct tags. feel free to move it to the correct place if I made a mistake.

This was discussed previously at

@MatthijsBlom thanks for the very quick answer. at least now I know where to post my questions. I’ll continue in the appropriate posts.