Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
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.
5 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 than
four characters. Use $0 as you iterate through the values of the array. Print the resulting collection.
Olet 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, 20]
expand button
Transcribed Image Text: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. 5 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 than four characters. Use $0 as you iterate through the values of the array. Print the resulting collection. Olet 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, 20]
Expert Solution
Check Mark
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.

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.

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.
Knowledge Booster
Background pattern image
Computer Science
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education