[swift-users] Appending '[element]' recursively

Dmitri Gribenko gribozavr at gmail.com
Mon Jun 27 11:38:33 CDT 2016


On Mon, Jun 27, 2016 at 7:48 AM, Adriano Ferreira via swift-users
<swift-users at swift.org> wrote:
> // Swift 3
>
> func quickSort(_ array: [Int]) -> [Int] {
>     guard array.count > 1 else {
>         return array
>     }
>
>     let (pivot, rest) = (array.first!, array.dropFirst())
>
>     let lessThan = rest.filter({ $0 < pivot })
>     let greaterThanOrEqual = rest.filter({ $0 >= pivot })
>
>     // Cannot use ‘[Int]' here, as in Swift 2.2
>     // Error says 'Int' is not convertible to '[Int]'
>     let pivotArray = [pivot]
>     return quickSort(lessThan) + pivotArray + quickSort(greaterThanOrEqual)
> }

Hi Adriano,

This code compiles with the current git master.  Could you
double-check and post the exact error you are getting?

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-users mailing list