Exercise - Collection Functions Using the code below, use the map function to create an array of Int values, whose values are equal to the original integer value, plus 1. Use $0 as you iterate through the values of the array. Print the resulting collection. let testScores = [65, 80, 88, 90, 47] Using the code below, use the filter function to create a new array of String values. The new array should only include Strings longer tha four characters. Use $0 as you iterate through the values of the array. Print the resulting collection. let schoolSubjects = ["Math", "Computer Science", "Gym", "English", "Biology"] Using the code below, use the reduce function to subtract all of the values within the array from the starting value 100. Print the resulting value. let damageTaken = [25, 10, 15, 30, 201
Exercise - Collection Functions Using the code below, use the map function to create an array of Int values, whose values are equal to the original integer value, plus 1. Use $0 as you iterate through the values of the array. Print the resulting collection. let testScores = [65, 80, 88, 90, 47] Using the code below, use the filter function to create a new array of String values. The new array should only include Strings longer tha four characters. Use $0 as you iterate through the values of the array. Print the resulting collection. let schoolSubjects = ["Math", "Computer Science", "Gym", "English", "Biology"] Using the code below, use the reduce function to subtract all of the values within the array from the starting value 100. Print the resulting value. let damageTaken = [25, 10, 15, 30, 201
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
Step 1: Algorithm
Part 1: testScores.map({$0 + 1})
- Algorithm:
- Initialize an array
testScores
with values [65, 80, 88, 90, 47]. - Apply a mapping operation to each element in
testScores
, adding 1 to each element. - Store the result in a new array called
testScoresPlusOne
. - Print the
testScoresPlusOne
array.
- Initialize an array
Part 2: schoolSubjects.filter({$0.count > 4})
- Algorithm:
- Initialize an array
schoolSubjects
with values ["Math", "Computer Science", "Gym", "English", "Biology"]. - Apply a filtering operation to
schoolSubjects
, keeping only elements with a character count greater than 4. - Store the filtered elements in a new array called
longSubjects
. - Print the
longSubjects
array.
- Initialize an array
Part 3: damageTaken.reduce(100, {$0 - $1})
- Algorithm:
- Initialize an array
damageTaken
with values [25, 10, 15, 30, 20]. - Perform a reduction operation on
damageTaken
, starting with an initial value of 100. - Subtract each element in
damageTaken
from the accumulated result. - Store the final result in a variable called
remainingHealth
. - Print the
remainingHealth
variable.
- Initialize an array
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education