Last active
August 29, 2015 14:25
-
-
Save erica/62d9f1ecee14f301dd1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [2, 3, 5, 1, 6, 9, 8] | |
extension Array where Element:Comparable { | |
var maxIndex : Int? { | |
// Thanks Mike Ash, Jacob Bandes-Storch, Bas Broek | |
return self.enumerate().maxElement({$1.element > $0.element})?.index | |
} | |
} | |
array.maxIndex | |
// Update: Thanks, Jordan Rose | |
// http://twitter.com/UINT_MIN/status/624274556098842624 | |
extension CollectionType where Generator.Element: Comparable { | |
var maxIndex : Index? {return self.indices.maxElement({self[$1] > self[$0]})} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 very cool!