CtCI-6th-Edition-Swift icon indicating copy to clipboard operation
CtCI-6th-Edition-Swift copied to clipboard

Combine `contains` and `insert` into one

Open amomchilov opened this issue 4 years ago • 0 comments

https://github.com/careercup/CtCI-6th-Edition-Swift/blob/0dbf24e622df4ef8dbac383711c3b8629a87d477/Ch%202.%20Linked%20Lists/Ch%202.%20Linked%20Lists.playground/Pages/2.1%20Remove%20Duplicates.xcplaygroundpage/Contents.swift#L10-L11

Could be re-written as:

guard set.insert($1).inserted else { return $0 }

It's more canonical, and makes the value only need to get hashed once.

amomchilov avatar Apr 13 '20 18:04 amomchilov