You are viewing a single comment's thread. Return to all comments →
I don't see any Swift solution yet (which is weird). So I post a "Swifty" solution:
func minimumAbsoluteDifference(arr: [Int]) -> Int { let arrSorted = arr.sorted() return arr.sorted().dropLast().enumerated().reduce(Int.max, { (acc, nextEl) in let current = nextEl.element let next = arrSorted[nextEl.offset+1] return min(acc, abs(current-next)) }) }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Absolute Difference in an Array
You are viewing a single comment's thread. Return to all comments →
I don't see any Swift solution yet (which is weird). So I post a "Swifty" solution: