Hi Tod, thanks for sharing your ideas. Much appreciated!
Feel free to take a look at my playground where I explore many other
alternative implementations.
https://github.com/adrfer/Sort/tree/swift-3
Best,
— A
> On Jun 30, 2016, at 11:32 AM, Tod Cunningham via swift-users
>
This was bugging me last night, as I still didn’t like the solution. What
about something like:
func selectionSort(_ originalArray: [Int]) -> [Int] {
var array = originalArray
for index in 0.. wrote:
Was trying to using some functional programming concepts while also using as
little
On Tue, Jun 28, 2016 at 9:58 PM, Erica Sadun wrote:
> Most everyone is doing two passes, one to get the minimum value, another
> to get its index.
> I aesthetically prefer using enumerate to do both at once.
>
> -- E
>
Makes sense. Here’s a revision. It’s not as simple,
>
> On Jun 28, 2016, at 8:18 PM, Dan Loewenherz via swift-users
> wrote:
>
> I’m not sure if you wanted to stick with the pure functional approach, but
> here’s an alternative that uses Range to take care of most of the work.
>
> func selectionSort(_ array: [Int]) ->
I’m not sure if you wanted to stick with the pure functional approach, but
here’s an alternative that uses Range to take care of most of the work.
func selectionSort(_ array: [Int]) -> [Int] {
guard let minValue = array.min(), let index = array.index(of: minValue)
else {
return []
Hi everyone!
I’m experimenting with this functional selection sort code and I wonder if
anyone could help me simplify the portion indicated below.
// Swift 3
func selectionSort(_ array: [Int]) -> [Int] {
guard array.count > 1, let minElement = array.min() else {
return array