We have updated the content of our program. To access the current Software Engineering curriculum visit curriculum.turing.edu.
Array Exercises
Mild Practice
Calculate Daily Pay
Trisha gets paid $22 each time she walks a dog. The array below holds 7 numbers, the number of dog walks she took each day last week. Iterate over the array, and print out “Trisha earned $__ today!” for each day.
var dogWalks = [4, 5, 2, 2, 6, 1, 3]
YELLING
Iterate over an array of strings. For each string, print out the YELLING version of it. Look into how to convert a string to uppercase!
Medium Practice
Calculate Total Pay
Trisha gets paid $22 each time she walks a dog. The array below holds 7 numbers, the number of dog walks she took each day last week. Write a function that takes one argument, an Array of Numbers, and that returns her total pay.
var dogWalks = [4, 5, 2, 2, 6, 1, 3]
Best Client
Kayla gets paid various amounts by each client for a dog walk. The array below holds 7 numbers, the hourly amounts. Write a function that takes one argument, an Array of Numbers, and that returns her highest paying dog-walking gig.
If this were the array representing Kayla’s different hourly rates: var hourlyPay = [22, 17, 29, 16, 18]
, this function should return the Number 29.
Spicy Practice
Sum of Two
Write a function that takes one argument, an Array of Numbers. It should return the sum of the two lowest positive numbers in that array (an array with a minimum of 4 numbers will be passed in). No empty arrays will be passed in. For example, when an array is passed in like [19, 5, 42, 2, 77]
, the output should be 7
because 5 + 2 = 7
.
Find the Odd (or Even) One Out
Write a function that takes in one argument - an array of numbers. The array must have at least 3 elements. All numbers except for one of them will be either even or odd. You job is to return that one number that is the exception. Below are some example inputs and outputs. Make sure your function works on them all.
Input: [1, 3, 5, 6]
, Output: 6
Input: [10, 15, 20, 30, 40, 50]
, Output: 15
Input: [19, 5, 42, 1, 77]
, Output: 42