From d41e56022be2226399fe981f0258a22c716098b4 Mon Sep 17 00:00:00 2001 From: Dahna Buenrostro Date: Mon, 9 Mar 2020 18:47:12 -0400 Subject: [PATCH] Completed Project I completed all of the steps to the project to the best of my ability --- NOCList.playground/Contents.swift | 113 +++++++++++++----- .../UserInterfaceState.xcuserstate | Bin 0 -> 9076 bytes 2 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 NOCList.playground/playground.xcworkspace/xcuserdata/Dahna.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/NOCList.playground/Contents.swift b/NOCList.playground/Contents.swift index 71c2654..0c44909 100644 --- a/NOCList.playground/Contents.swift +++ b/NOCList.playground/Contents.swift @@ -29,56 +29,105 @@ 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 agentEthanHunt = (coverName: "Ethan Hunt", realName: "Tom Cruise", accessLevel: 8, compromised: false) +let agentJimPhelps = (coverName: "Jim Phelps", realName: "Jon Voight", accessLevel: 9, compromised: true) +let agentClairePhelps = (coverName: "Claire Phelps", realName: "Emmanuelle Beart", accessLevel: 5, compromised: false) +let agentEugeneKittridge = (coverName: "Eugene Kittridge", realName: "Henry Czerny", accessLevel: 10, compromised: true) +let agentFranzKrieger = (coverName: "Franz Krieger", realName: "Jean Reno", accessLevel: 4, compromised: false) +let agentLutherStickell = (coverName: "Luther Stickell", realName: "Ving Rhames", accessLevel: 4, compromised: false) +let agentSarahDavies = (coverName: "Sarah Davies", realName: "Kristin Scott Thomas", accessLevel: 5, compromised: true) +let agentMaxRotGrab = (coverName: "Max RotGrab", realName: "Vanessa Redgrave", accessLevel: 4, compromised: false) +let agentHannahWilliams = (coverName: "Hannah Williams", realName: "Ingeborga Dapkūnaitė", accessLevel: 5, compromised: true) +let agentJackHarmon = (coverName: "Jack Harmon", realName: "Emilio Estevez", accessLevel: 6, compromised: true) +let agentFrankBarnes = (coverName: "Frank Barnes", realName: "Dale Dye", accessLevel: 9, compromised: false) //: ## Step 2 //: Place the above constants inside an array. Declare this array as a constant as well. - - - +let secretAgents = [agentEthanHunt, agentJimPhelps, agentClairePhelps, agentEugeneKittridge, agentFranzKrieger, agentLutherStickell, agentSarahDavies, agentMaxRotGrab, agentHannahWilliams, agentJackHarmon, agentFrankBarnes] //: ## 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 compromisedAgents() -> Int { + var count = 0 + for agent in secretAgents { + if agent.compromised == true { + count += 1 + } + } + return count +} //: ## 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. - - - +compromisedAgents() +let totalCompromised = compromisedAgents() +print("\(totalCompromised) agents 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. - - - +var cleanAgents: [String] = [] + +func findCleanAgents() -> [String] { + for agent in secretAgents { + if agent.compromised == false { + cleanAgents.append(agent.0) + print(agent.0) + } + } + 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("\(cleanAgents.count) clean agents out of \(secretAgents.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 highRiskAgent in secretAgents { + if highRiskAgent.accessLevel >= 8, + highRiskAgent.compromised == true { + print("\(highRiskAgent.realName), level: \(highRiskAgent.accessLevel) **WARNING** **COMPROMISED**") + } else if highRiskAgent.accessLevel >= 8, + highRiskAgent.compromised == false { + print("\(highRiskAgent.realName), level: \(highRiskAgent.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 agentLevelSort() { + + var lowLevelAgents = 0 + var midLevelAgents = 0 + var highLevelAgents = 0 + + for agent in secretAgents { + switch agent.accessLevel { + case 0...4: + lowLevelAgents += 1 + case 5...7: + midLevelAgents += 1 + default: + highLevelAgents += 1 + } + } + print("\(lowLevelAgents) low level agents, \(midLevelAgents) mid level agents, and \(highLevelAgents) high level agents") +} //: ## Step 10 //: Call the above function and check its output in the console. - - - +agentLevelSort() //: ## 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 agentList() { + + let sortedAgents = secretAgents.sorted { + $0.accessLevel < $1.accessLevel + } + + for agent in sortedAgents { + print("\(agent.coverName) \(agent.accessLevel)") + } +} + +agentList() diff --git a/NOCList.playground/playground.xcworkspace/xcuserdata/Dahna.xcuserdatad/UserInterfaceState.xcuserstate b/NOCList.playground/playground.xcworkspace/xcuserdata/Dahna.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000000000000000000000000000000000000..f2da40b45160a10e973c426b7da80fc5afbc8530 GIT binary patch literal 9076 zcmeHMd3;k<_CNO~X_97pFH50GV~Z_2-8ahGB`uVtR7%+)rp;>`Xp@knKtc2hsHlLT zB7z{aMLGe3Xo$nU)OnzR+>xBdNVKW*~fJ@=k- z&pqdRmRlEW_Jt!^S?7TO1qCQU1#zH;_?c;og;3ZR@Xt!~gzB4o_%tmo5(v&r3)C$T z>LXz@kUMv}Ia5{5M4?UamUI!l2O7}U)wS^nt#R2t#2Qq(cT|LKb90 z4&*`^xS$*=U>uBxO7Ot~SP0F~0)7ZU5EelQ!VrO0SPV;GDYU_Dz~BzJ4>rI?xE~&X z2VoOD0*}FN*aJ_%0XPWH!1M4D{082D)9@agg$r;Ieh2>sSKu@F0=|YH;6LC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