Your question is Code Review a Stack Implementation. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Staffline Solutions built an undo stack so a scheduler can step back through recent edits to a shift roster. Here is the implementation a backend engineer put up for review.
package scheduling
type ShiftEditStack struct {
items []string
top int
}
func NewShiftEditStack() *ShiftEditStack {
return &ShiftEditStack{items: make([]string, 10), top: 0}
}
func (s *ShiftEditStack) Push(edit string) {
s.items[s.top] = edit
s.top++
}
func (s *ShiftEditStack) Pop() string {
s.top--
return s.items[s.top]
}
func (s *ShiftEditStack) Peek() string {
return s.items[s.top]
}
func (s *ShiftEditStack) IsEmpty() bool {
return s.top == 0
}
Review this implementation. What do you look for and how would you improve it before this ships to production?