From d26c122f7a726a18e16ff99e1f4b689493282351 Mon Sep 17 00:00:00 2001 From: michelespoldi Date: Tue, 1 May 2018 08:33:18 +0200 Subject: [PATCH 1/2] Arrays lab 1 completed --- .../main.xcplaygroundpage/Contents.swift | 99 +++++-------------- 1 file changed, 25 insertions(+), 74 deletions(-) diff --git a/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift b/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift index f77d3a8..6b886e2 100644 --- a/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -11,118 +11,69 @@ /*: question1 ### 1. Write an array called 'list' **without** a type specified that contains the string values "Bread", "Butter", "Cheese", "Lettuce", "Tomatoes". */ - // write your code here - - - - - + var list = ["Bread", "Butter", "Cheese", "Lettuce", "Tomatoes"] + print(list[2]) /*: question2 ### 2. Write an array called 'shoppingList' **with** a type specified that contains the string values "Bread", "Butter", "Cheese", "Lettuce", "Tomatoes". */ -// write your code here - - - - +var shoppingList: [String] = ["Bread", "Butter", "Cheese", "Lettuce", "Tomatoes"] +print(shoppingList[0]) /*: question3 ### 3. Initialize an array called 'futureShoppingList' **with** a type specified and then add the string values "Bread", "Butter", "Cheese", "Lettuce", "Tomatoes". */ -// write your code here - - - - +var futureShoppingList: [String] +futureShoppingList = ["Bread", "Butter", "Cheese", "Lettuce", "Tomatoes"] +print(futureShoppingList[4]) /*: question4 ### 4. Write an array called 'cheeseSandwich' **with** a type specified whose value will never change (constant) and contains the string values "Bread", "Butter", "Cheese", "Lettuce", "Tomatoes". */ -// write your code here - - - - - +let cheeseSandwich: [String] = ["Bread", "Butter", "Cheese", "Lettuce", "Tomatoes"] +print(cheeseSandwich[1]) /*: question5 ### 5. Create a second array called 'dessertList' with a type specified which contains the string values "Cookie dough", "Icecream" */ -// write your code here - - - - - - +var dessertList: [String] = ["Cookie dough", "Icecream"] /*: question6 ### 6. Write an array called 'afternoonAttendance' **with** a type specified that contains the integer values 2, 10, 3, 15, 7. */ -// write your code here - - - - - - - +var afternoonAttendence: [Int] = [2, 10, 3, 15, 7] +print(afternoonAttendence[2]) /*: question7 ### 7. Assign the value at the second position in the 'shoppingList' array to a variable called 'itemToPrint' and print it to the screen. */ -// write your code here - - - - - - - +let itemToPrint = shoppingList[1] +print(itemToPrint) /*: question8 ### 8. Change the value of 'Cheese' in the 'futureShoppingList' array to 'Chicken' and then print the array to the console. */ -// write your code here - - - - - - - +futureShoppingList[2] = "Chicken" +print(futureShoppingList[2]) /*: question9 ### 9. Create a function named 'lifesEssential' that accepts an array of strings as a parameter called 'ingredients' and returns a boolean. Inside the function, check to see if the array passed to the function contains the value "Bread" at position 0. If it does, return a true value, if not false. */ -// write your code here - - - - - - +func lifeEssentials(ingredients: Array) -> Bool { + if ingredients[0] == "Bread" { + return true + } else { + return false + } +} /*: question10 ### 10. Pass the 'shoppingList' array to the 'lifesEssential' function and print the result (the result being the value which is returned as a result to the call to the lifesEssential function). */ -// write your code here - - - - - - - - +print(lifeEssentials(ingredients: shoppingList)) /*: question11 ### 11. Pass the 'desertList' array to the 'lifesEssential' function and print the result. */ -// write your code here - - - - +print(lifeEssentials(ingredients: dessertList)) //: Click [here](https://github.com/learn-co-curriculum/swift-arrays-lab/blob/solution/Arrays.playground/Pages/solution.xcplaygroundpage/Contents.swift) for the solution. From 712b72940725928ba52ade60481a4284a847c0d4 Mon Sep 17 00:00:00 2001 From: michelespoldi Date: Tue, 1 May 2018 08:35:17 +0200 Subject: [PATCH 2/2] lab_1_completed --- Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift b/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift index 6b886e2..4ce37d6 100644 --- a/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/Arrays.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -11,9 +11,9 @@ /*: question1 ### 1. Write an array called 'list' **without** a type specified that contains the string values "Bread", "Butter", "Cheese", "Lettuce", "Tomatoes". */ - var list = ["Bread", "Butter", "Cheese", "Lettuce", "Tomatoes"] +var list = ["Bread", "Butter", "Cheese", "Lettuce", "Tomatoes"] - print(list[2]) +print(list[2]) /*: question2 ### 2. Write an array called 'shoppingList' **with** a type specified that contains the string values "Bread", "Butter", "Cheese", "Lettuce", "Tomatoes". */