Giter Site home page Giter Site logo

swift-arraychallenge-lab-ios-0616's Introduction

Shopping Time

Dorothy

Toto, I've got a feeling we're not in Kansas anymore. ~Dorothy Gale

Learning Objectives

  • Write a method that takes in two arguments and returns an Array.
  • Call on created method in viewDidLoad().
  • Read and run unit tests to check your work.

Instructions

CuteCat

Our adorable cat, Ginger, has been somewhat of a brat lately. We had a nice shopping list all ready to go which included the items we needed at the store, along with the number of each item we needed to purchase. But, Ginger got to it. The list has been torn directly in half, with one piece of paper with just numbers on it (representing the number of each item needed) and one piece of paper with just the items on it.

It's your job (the programmer) to create a function which will take in two arguments. One of these arguments will be of type [String] which represents the various items. The other argument will be of type [Int] which represents the quantity of each item. Considering the list was split in half, they match up evenly. You need to return back an array of type [String] which represents a complete shopping list.

On one sheet of paper, we have the following:

  • 6
  • 4
  • 12
  • 4

On the other sheet of paper, we have:

  • Bananas
  • Apples
  • Eggs
  • Rolls

Your function should return back an array that produces a list that looks like this:

  1. 6 Bananas
  2. 4 Apples
  3. 12 Eggs
  4. 4 Rolls
  1. In the viewDidLoad() method in the ViewController.swift file, you should create two separate arrays that represent the torn sheets of paper. [6, 4, 12, 4] & ["Bananas", "Apples", Eggs", Rolls].
  2. Create a function which will take in two arguments of type [String] and [Int] which returns an array of type [String]. This array should represent our completed shopping list shown above. In order for the tests to work, your methods signature should be this: makeShoppingList(_:quantityOfItems:).
  3. Call on this function in viewDidLoad() and assign the return value of this function to the shoppingList variable which has already been created for you (above the viewDidLoad() method.

Quick Note. How do you read that method signature I included in instruction #2? The name of this function should be makeShoppingList, that underscore _ means that the first argument to this function will have NO external name when it is called which happens by default. The second argument to this function will have an external name of quantityOfItems when it is called.

Here's an example.

func printFavoriteNames(names: [String], colors: [String], numbers: [Int]) {
	// printing all my favorite names, colors and numbers
}

We call on this function like so:

let names = ["Jim", "Bran", "Sansa"]
let colors = ["Red", "Blue", "Green"]
let numbers = [7, 742, 5]

printFavoriteNames(names, colors: colors, numbers: numbers)

Notice how when calling the function, the first argument's external name is not there but colors: and numbers: is. So if we were to type out this method signature to someone, we would do so like this:

printFavoriteNames(_:colors:numbers:)

View this lesson on Learn.co

swift-arraychallenge-lab-ios-0616's People

Contributors

ezaman avatar jimcampagno avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.