Make us do code that has no bearing on the lesson

@script5162516623, I agree with this reply and the lack of logic. The instructions say one thing and make us do code that has no bearing on the lesson. Maybe it’s trying to kill multiple birds with the one stone (poor birds) for making the course more concise and smaller but as beginners to this, we’d prefer to see it as clearly and simply as possible and then have other more ‘colourful’ concepts introduced later. I can totally see the logic of pop as its entirely normal to remove items from an array but for a method that’s supposed to ‘remove’ something, the result is that it’s NOT removed but just got saved somewhere else. Weird logic from the course creator. Maybe this is a very common use case (no idea, not enough experience to say) and it was necessary to show the primary use cases but it certainly needs better explanation.

As we see in the example, the element is indeed removed from the array. It is not just evaporated into the ether, though, but optionally assigned to a variable for further use. There is nothing ‘weird’ going on here. It is all very practical.

Maybe weird is the wrong word. I suppose my problem is with the objective of the lesson, to explain ‘pop()’. For example I’m still trying to understand the use cases for pop - for sure there are many but as a beginner to this I’m trying to understand why I’d want to knock one single element of the end of a list either just once or very regularly. So trying to understand pop at it’s simplest is a mini struggle for me, then to introduce pop removals being captured by another variable is like 2 levels higher than where I am. Maybe I’m just a touch slow.

Let’s say we have a card game with two players such as gin rummy. There are six collections involved.

  • the 52 card deck
  • hand one
  • hand two
  • outlay one
  • outlay two
  • discard pile

When we have shuffled the deck, we deal out the two initial hands.

hand1.push(deck.pop())
hand2.push(deck.pop())

That would be in a loop until seven cards are dealt to each hand. The cards have been removed from the deck so they cannot be drawn again.