Skip to content

Commit

Permalink
using min
Browse files Browse the repository at this point in the history
  • Loading branch information
decanus committed May 18, 2020
1 parent 506e3e7 commit 61bdfe6
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions Sources/UB/Extensions/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@ import Foundation

extension Array where Element == Addr {
func closest(to: Addr) -> Addr? {
var distance = 0
var addr: Addr?

forEach { peer in
let dist = peer.distance(to: to)
if distance > dist {
distance = dist
addr = peer
}
return self.min { a, b in
a.distance(to: to) < b.distance(to: to)
}

return addr
}
}

0 comments on commit 61bdfe6

Please sign in to comment.