Skip to content

Commit 3db2bc6

Browse files
committed
Using isEmpty instead of count for the array pop method
1 parent 76cb661 commit 3db2bc6

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Stack/Stack.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ public struct Stack<T> {
1919
}
2020

2121
public mutating func pop() -> T? {
22-
if count == 0 {
23-
return nil
24-
} else {
25-
return array.removeLast()
26-
}
22+
guard !array.isEmpty else { return nil }
23+
24+
return array.removeLast()
2725
}
2826

2927
public func peek() -> T? {

0 commit comments

Comments
 (0)