Skip to content

Commit 183815a

Browse files
authored
implement guarded array first
1 parent 8e85522 commit 183815a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Select Minimum Maximum/Minimum.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
*/
44

55
func minimum<T: Comparable>(_ array: [T]) -> T? {
6-
guard !array.isEmpty else {
7-
return nil
8-
}
9-
10-
var minimum = array.first!
6+
guard minimum = array.first else { return nil }
7+
118
for element in array.dropFirst() {
129
minimum = element < minimum ? element : minimum
1310
}

0 commit comments

Comments
 (0)