Instantly share code, notes, and snippets.

Embed
What would you like to do?
let penny = (nombre: "Penny", esChica: true)
let amy = (nombre: "Amy", esChica: true)
let bernadette = (nombre: "Bernadette", esChica: true)
let sheldon = (nombre: "Shedon", esChica: false)
let leonard = (nombre: "Leonard", esChica: false)
let howard = (nombre: "Howard", esChica: false)
let raj = (nombre: "Raj", esChica: false)
let elenco = [ penny, amy, bernadette, sheldon, leonard, howard, raj ]
let personajesFemeninos = elenco.filter({ $0.esChica })
print(personajesFemeninos)
// [(nombre: "Penny", esChica: true), (nombre: "Amy", esChica: true), (nombre: "Bernadette", esChica: true)]
let soloLosNombres = personajesFemeninos.map({ $0.nombre })
print(soloLosNombres)
// ["Penny", "Amy", "Bernadette"]
let sumaDeLetras = soloLosNombres.reduce(0) { $0 + $1.count }
print(sumaDeLetras)
// 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment