Created
December 18, 2019 10:49
-
-
Save juliengdt/87e82378bdf2cb51377d09e80ca4d015 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 otherTableau: Array<(Int, String)> = [(1,"a"),(2,"b"),(3,"c"),(4,"d")] | |
let mean = otherTableau.map { tuple -> Int in | |
return tuple.0 | |
} | |
/* | |
On peut aussi écrire le map de mean de cette facon, pour raccourcir l'écriture | |
"$0" est "le premier argument" | |
dans ce cas là pas besoin de "return" , swift est assez intelligent pour comprendre ce que tu veux faire | |
let mean = otherTableau.map{ $0.0 } | |
*/ | |
let _mean = mean.reduce(0,+)/mean.count | |
print(_mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment