Skip to content

Instantly share code, notes, and snippets.

@keremvatandas
Created February 16, 2019 12:51
Show Gist options
  • Select an option

  • Save keremvatandas/0e95793748617a8b39f737f3a17359bb to your computer and use it in GitHub Desktop.

Select an option

Save keremvatandas/0e95793748617a8b39f737f3a17359bb to your computer and use it in GitHub Desktop.

Revisions

  1. keremvatandas created this gist Feb 16, 2019.
    18 changes: 18 additions & 0 deletions swiftgenerics.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    func getMax<T: Comparable>(dizi a: [T]) -> T
    {
    var max = a[0]

    for i in 1..<a.count {
    if max < a[i] {
    max = a[i]
    }
    }

    return max
    }

    let sayiDizisi = [97, 34, 1, 129, 444]
    getMax(dizi: sayiDizisi) // 444

    let sayiDizisi2 = [97.0, 97.12, 1, 97.88, 97.9]
    getMax(dizi: sayiDizisi2) // 97.90000000000001