How do you find a maximum value in a Swift dictionary? -
so, have dictionary looks this:
var data : [float:float] = [0:0,1:1,2:1.414,3:2.732,4:2,5:5.236,6:3.469,7:2.693,8:5.828,9:3.201]
how programmatically find highest value in dictionary? there "data.max" command or something?
let maximum = data.reduce(0.0) { max($0, $1.1) }
just quick way using reduce
.
or:
data.values.maxelement()
output:
print(maximum) // 5.828
Comments
Post a Comment