Skip to content

Instantly share code, notes, and snippets.

@juliengdt
Created December 18, 2019 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliengdt/87e82378bdf2cb51377d09e80ca4d015 to your computer and use it in GitHub Desktop.
Save juliengdt/87e82378bdf2cb51377d09e80ca4d015 to your computer and use it in GitHub Desktop.
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