Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete project #53

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 89 additions & 45 deletions NOCList.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*:
# Module Project - NOC List

Greetings agent. Your mission is a top priority for the agency. Please read below for further info.

Our undercover agents in Eastern Europe are in trouble. The NOC list (Non-official cover) has been leaked and we need our directors to have quick access to the information so we can try to mitigate the damage. Some of the agents on the list have an access level that makes them privy to very sensitive information. We need an application that will present the NOC list's information in a quickly digestible format. Our top agents have been working on it, but we need this done ASAP and you've proven yourself to be quite capable of a quick turnaround.

The Director herself has given you access to all the agency's resources to complete this mission. We're counting on you agent.

Here is the complete NOC List. This information is classified at the highest levels, so guard it very carefully.

# Module Project - NOC List
Greetings agent. Your mission is a top priority for the agency. Please read below for further info.
Our undercover agents in Eastern Europe are in trouble. The NOC list (Non-official cover) has been leaked and we need our directors to have quick access to the information so we can try to mitigate the damage. Some of the agents on the list have an access level that makes them privy to very sensitive information. We need an application that will present the NOC list's information in a quickly digestible format. Our top agents have been working on it, but we need this done ASAP and you've proven yourself to be quite capable of a quick turnaround.
The Director herself has given you access to all the agency's resources to complete this mission. We're counting on you agent.
Here is the complete NOC List. This information is classified at the highest levels, so guard it very carefully.
---

* coverName: "Ethan Hunt", realName: "Tom Cruise", accessLevel: 8, compromised: false
Expand All @@ -24,61 +24,105 @@ Here is the complete NOC List. This information is classified at the highest lev
* coverName: "Frank Barnes", realName: "Dale Dye", accessLevel: 9, compromised: false

---

This message will self destruct in 5 seconds.
*/
This message will self destruct in 5 seconds.
*/
//: ## Step 1
//: Create constants for each of the above agents and store all their information in a tuple.



let ethanHunt = (coverName: "Ethan Hunt", realName: "Tom Cruise", accessLevel: 8, compromised: false)
let jimPhelps = (coverName: "Jim Phelps", realName: "Jon Voight", accessLevel: 9, compromised: true)
let clairePhelps = (coverName: "Claire Phelps", realName: "Emmanuelle Beart", accessLevel: 5, compromised: false)
let eugeneKittridge = (coverName: "Eugene Kittridge", realName: "Henry Czerny", accessLevel: 10, compromised: true)
let franzKrieger = (coverName: "Franz Krieger", realName: "Jean Reno", accessLevel: 4, compromised: false)
let lutherStickell = (coverName: "Luther Stickell", realName: "Ving Rhames", accessLevel: 4, compromised: false)
let sarahDavies = (coverName: "Sarah Davies", realName: "Kristin Scott Thomas", accessLevel: 5, compromised: true)
let maxRotGrab = (coverName: "Max RotGrab", realName: "Vanessa Redgrave", accessLevel: 4, compromised: false)
let hannahWilliams = (coverName: "Hannah Williams", realName: "Ingeborga Dapkūnaitė", accessLevel: 5, compromised: true)
let jackHarmon = (coverName: "Jack Harmon", realName: "Emilio Estevez", accessLevel: 6, compromised: true)
let frankBarnes = (coverName: "Jack Harmon", realName: "Emilio Estevez", accessLevel: 6, compromised: true)
//: ## Step 2
//: Place the above constants inside an array. Declare this array as a constant as well.



let agents = [ethanHunt, jimPhelps, clairePhelps, eugeneKittridge, franzKrieger, lutherStickell, sarahDavies, maxRotGrab, hannahWilliams, jackHarmon, frankBarnes]
//: ## Step 3
//: Create a function that calculates the total number of compromised agents. Inside the function, iterate over the array of agents to determine which ones are compromised. Return the total count.



func compromised() -> Int {
var totalCompromised = 0

for agent in agents {
if agent.compromised == true {
totalCompromised += 1
}
}

return totalCompromised
}
//: ## Step 4
//: Call the above function to find the total number of compromised agents and then print a sentence that says "# agents have been compromised!" using string interpolation.



compromised()
print("\(compromised()) have been compromised!")
//: ## Step 5
//: Create a function called "findCleanAgents" that both prints the cover names of all uncompromised agents, as well as returns an array of agents that are uncompromised.



func findCleanAgents() -> [String]{
var cleanAgents = [String]()
for agent in agents {
if agent.compromised == false {
print(agent.coverName)
cleanAgents.append(agent.coverName)
}
}
return cleanAgents
}
//: ## Step 6
//: Call the above function to find the total number of clean agents and print a message that says "# clean agents out of # total agents." Use the total number of agents in the array from step 2 as the second number in the string.



findCleanAgents()
print("\(findCleanAgents().count) of clean agents out of \(agents.count) total agents.")
//: ## Step 7
//: Create a function called "findHighRisk" that prints out the real names and access levels of agents with level 8 or higher. If one of these agents is also currently compromised, add `**WARNING** **COMPROMISED**` to the end of the string that includes their name and access level.
//: - Example: `Jon Voight, level: 9 **WARNING** **COMPROMISED**`



func findHighRisk() {
for agent in agents {
if agent.accessLevel >= 8 && agent.compromised == true {
print("\(agent.realName), level: \(agent.accessLevel) **WARNING** **COMPROMISED**")
} else if agent.accessLevel >= 8 {
print("\(agent.realName), level: \(agent.accessLevel)")
}
}
}
//: ## Step 8
//: Call the above function and check the output in the console to ensure it is functioning properly.



findHighRisk()
//: ## Step 9
//: Create a function that finds totals for low, mid, and high level agents. Low level agents are 4 or lower, mid are 5-7, and high level agents are 8 or above. Iterate over each agent and use a `switch` statement to determine their level group. At the end of the function, print a statement like the following: "# low level agents, # mid level agents, and # high level agents"



func findAgentLevel() {
var low = 0
var mid = 0
var high = 0

for agent in agents {
switch agent.accessLevel {
case 0...4:
low += 1
case 5...7:
mid += 1
default:
high += 1
}
}

print("\(low) low level agents, \(mid) mid level agents and \(high) high level agents")
}
//: ## Step 10
//: Call the above function and check its output in the console.



findAgentLevel()
//: ## Step 11 (Optional)
//: Create and call a function that prints the cover names and access levels of all agents, but the list should be sorted by access level, in ascending order.


func agentsAccessLevel() {

let sortedAgents = agents.sorted(by: { $0.accessLevel < $1.accessLevel })

for agent in sortedAgents {
print("\(agent.coverName), level: \(agent.accessLevel)")
}
}

agentsAccessLevel()
Binary file not shown.