Last active
December 1, 2015 19:04
-
-
Save jsorge/140d42e710b5f39f59ad to your computer and use it in GitHub Desktop.
Trying to work out how to remove these nasty loops...
This file contains 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
//: Playground - noun: a place where people can play | |
import UIKit | |
struct Person { | |
let name: String | |
let isCool: Bool? | |
} | |
struct Department { | |
let name: String | |
let workers: [Person] | |
} | |
let tech = Department(name: "Tech", workers: [Person(name: "Jared", isCool: true), Person(name: "Emily", isCool: true), Person(name: "Atticus", isCool: true), Person(name: "Josh", isCool: nil)]) | |
let facilities = Department(name: "Facilities", workers: [Person(name: "Aaron", isCool: true), Person(name: "Joe", isCool: nil), Person(name: "Alex", isCool: nil), Person(name: "Will", isCool: true)]) | |
let company = [tech, facilities] | |
//I want to remove lines 22 - 29, and collapse them into 1 declaration: | |
//It would be `let coolPeople = ...` | |
var coolPeople = [Person]() | |
for department in company { | |
for person in department.workers { | |
if let _ = person.isCool { | |
coolPeople.append(person) | |
} | |
} | |
} | |
print(coolPeople) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment