Skip to content

Instantly share code, notes, and snippets.

@raymak
Last active November 18, 2019 04:07
Show Gist options
  • Save raymak/c6fec1e09957ed96277e2d0ceb257bfb to your computer and use it in GitHub Desktop.
Save raymak/c6fec1e09957ed96277e2d0ceb257bfb to your computer and use it in GitHub Desktop.

Problem 1

The following code defines two arrays of laptop models and their respective costs. Assume that the array is arbitrary and can be different each time we run the program (your program should work for any array).

var models: [String] = ["acer-aspire-5", "lenovo-ideapad", "acer-chromebook", "asus", "hp-touchscreen"]
var costs: [Double] = [499.98, 599.99, 269.99, 369.99, 799.99]

a. Print the length of the array and print the array is empty if the length is 0. b. Print the first and the last models in the array with their costs c. Print all models that cost more than $400. d. Print the sum of all the costs. e. Print the average of all the costs. f. Imagine the store wants to put all the laptops on sale for 20% off. Change the costs in the costs array so that they reflect the new prices.

Problem 2

Print all numbers 100 to 999 (inclusive of both) that are divisible by 17.

Problem 3

Given an arbritrary array (e.g. the one below), print every second element of it.

var arr = [-2, 0, 10, 16, 9, 92, 11, -7, 0, 0 , 18]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment