Stack examples

These examples push two report actions and pop them in reverse order, demonstrating last-in, first-out behavior.

Python

def print_label_value(label, value):
    print(f"\033[1;36m{label}:\033[0m {value}")

recent_actions = []
recent_actions.append("Changed assignee")
print_label_value("1. Push Changed assignee", "Changed assignee")

recent_actions.append("Changed priority")
print_label_value("2. Push Changed priority", "Changed priority")

print_label_value("3. Pop", recent_actions.pop())
print_label_value("4. Pop", recent_actions.pop())
print_label_value("5. Stack status", "empty" if not recent_actions else "has actions")

JavaScript

function printLabelValue(label, value) {
  console.log(`\x1b[1;36m${label}:\x1b[0m`, value);
}

const recentActions = [];
recentActions.push("Changed assignee");
printLabelValue("1. Push Changed assignee", "Changed assignee");

recentActions.push("Changed priority");
printLabelValue("2. Push Changed priority", "Changed priority");

printLabelValue("3. Pop", recentActions.pop());
printLabelValue("4. Pop", recentActions.pop());
printLabelValue(
  "5. Stack status",
  recentActions.length === 0 ? "empty" : "has actions",
);

Expected output

1. Push Changed assignee: Changed assignee
2. Push Changed priority: Changed priority
3. Pop: Changed priority
4. Pop: Changed assignee
5. Stack status: empty