The Deli Counter is counting down my patience!

Let’s just say I’m two months in the deli challenge with no way out. Let’s just say I see the sausage in front of me, just passing by on that sushi belt but with no way to reach it. Let’s just say it has been two months with no treats. I’m a cat too, I need to be treated like a cat!

OK, enough of this. Let me Google.

As I’m going through the Deli Counter challenge, it’s clear to me there are three main things to accomplish:

  • If there’s no one in line, say so.

  • If there’s a line, help people stay sane by telling them where they are in line.

  • If it’s someone’s turn, help them celebrate that small victory in their day, and swiftly send them on their way out of the line.

Supposedly simple, definitely not so.

One of the challenges that I met was with the mixing definitions of the number of people in a katz_deli, a queue, and the customer’s position in the queue. Quite helpful to make these distinction because then it helps with the strings later on.

SETTING UP katz_deli:

katz_deli = []  
def line(katz_deli) 
   position = 1 
   queue = []

DISPLAYING WHEN THE DELI IS EMPTY:

   if katz_deli.length == 0     
      puts "The line is currently empty."   
   else 
      katz_deli.each do |customer|     
      queue.push("#. #")     
      position +=1   
   end   
   puts "The line is currently: #{queue.join(" ")}"   
   end 
end

MANAGING THE QUEUE STATUS:
I’ve found that the exercise (now simply) allows various use of :

  • .push - adding to the end of an array

  • .join - concatenate into an array

  • .shift - remove from the beginning of an array

  • .empty? - checking if an array is empty

def take_a_number(katz_deli, customer)   
   katz_deli.push(customer)   
   puts "Welcome, #. You are number # in line." 
end  

def now_serving(katz_deli)   
   if katz_deli.empty?     
      puts "There is nobody waiting to be served!"   
   else     
      puts "Currently serving #."   
      katz_deli.shift 
   end 
end

I’ve really struggle with coming up with a fresh-from-the-start solution, as if I’m Ada Lovelace inventing computer languages for the first time. It’s more clear to me now that in order to learn, I need to tread on the path that my fore friends have gone before me. Googling and learning from past solutions are not a crime, it’s the learning of English vocabulary from simple TV programs before I could mimic a sentence and talk like an American with a broken English accent. This experience has kept me humble and push me to keep going.

Until the next struggle, my friends.