Skip to content

Instantly share code, notes, and snippets.


fitomad/array_funcional.swift Secret

Created Nov 19, 2018
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 })
// [(nombre: "Penny", esChica: true), (nombre: "Amy", esChica: true), (nombre: "Bernadette", esChica: true)]
let soloLosNombres ={ $0.nombre })
// ["Penny", "Amy", "Bernadette"]
let sumaDeLetras = soloLosNombres.reduce(0) { $0 + $1.count }
// 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment