Skip to content

Instantly share code, notes, and snippets.

@vishw33
Created April 11, 2018 17:16
Show Gist options
  • Select an option

  • Save vishw33/a460d71275d222b706763c1d196bdc9e to your computer and use it in GitHub Desktop.

Select an option

Save vishw33/a460d71275d222b706763c1d196bdc9e to your computer and use it in GitHub Desktop.

Revisions

  1. vishw33 created this gist Apr 11, 2018.
    21 changes: 21 additions & 0 deletions PersonArrayExtension.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    extension Array where Element == Person
    {
    func arrangePersonsByAge() -> [Element]
    {
    var arr = self
    arr.sort { (a, b) -> Bool in

    a.age > b.age
    }
    return arr
    }

    func arrangePersonsBySalary() -> [Element]
    {
    var arr = self
    arr.sort { (a, b) -> Bool in
    a.salary < b.salary
    }
    return arr
    }
    }