
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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]](https://content.bartleby.com/qna-images/question/3667c4e2-dfba-4518-b7aa-6b434ae74977/c8e13adb-ef14-4768-9967-9400545d697c/kdz64z_thumbnail.png)
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

arrow_forwardPart 1:
Part 2:
Part 3:
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 stepSolved 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.Similar questions
- Code in Perl Create an array which holds a list of Video Games, consisting of title, the year it was released (guess if you don’t know) , platform (NES, XBOX One, etc) and publisher (in that order). Add at least ten albums to the list. Then, use the split function and a for or foreach loop to display the publisher followed by the title and platform for each list element.arrow_forwardPyhton. NumPy. Please solvearrow_forward1. Display Function Implement a function to display the contents of the patient_list array. Add code to call this function. Note that there are multiple places where this function needs to be called. Look for the // TODO comments to find the correct locations. Compile and test your program. Make sure that your output is formatted similarly to the sample output shown at the end of this document. The sorting part does not need to work yet. Take a screenshot of a sample output and upload the picture as part of your assignment submission. 2. Sorting the array by Age Implement the code to sort the contents of the patient_list array based on the value stored in the age field. To do this you will need to implement code that relies on the qsort function from the C Standard library(see http://www.cplusplus.com/reference/cstdlib/qsort/). As shown in the reference, this code requires two parts: A function that compares two patient elements, based on the value stored in the age…arrow_forward
- PHP* Create a function that takes a list of numbers and returns the second largest number with the user input. Examples $array = user input (10, 20, 30, 40, 50) secondLargest([$array]) ➞ 40 Notes ● There will be at least two numbers in the array.arrow_forward// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forwardRemove Char This function will be given a list of strings and a character. You must remove all occurrences of the character from each string in the list. The function should return the list of strings with the character removed. Signature: public static ArrayList<String> removeChar(String pattern, ArrayList<String> list) Example:list: ['adndj', 'adjdlaa', 'aa', 'djoe']pattern: a Output: ['dndj', 'djdl', '', 'djoe']arrow_forward
- Using C Sharp, Declare an array animals with 5 animals in it such as “dog”, “cat”, etc. After the declaration write the code to add another animal to the array. Write the code to add each animal to a list box called lstAnimals.arrow_forward4. Array code Fill in the method below to have it create and fill in an array of 4 doubles. The first ele- ment should be set to the average of the first quarter of the array passed to data, the second element should be set to the average of the second quarter of the array, and so on. If input data is [1, 2, 3, 4, 5, 6, 7, 8] result should be [1.5, 3.5, 5.5, 7.5] public static double[] quartileAverages(int [] data) {arrow_forwardMatrix Multiplication• Write a multiplication function that accepts two 2D numpy arrays,and returns the product of the two. This function should test that thearrays are compatible (recall that the number of columns in the firstmatrix must equal the number of rows in the second matrix). Thisfunction should test the array sizes before attempting themultiplication. If the arrays are not compatible, the function shouldreturn -1. solve in pythonarrow_forward
- Create a function named "onlyOdd".The function should accept a parameter named "numberArray".Use the higher order function filter() to create a new array that only containsthe odd numbers. Return the new array.// Use this array to test your function:const testingArray = [1, 2, 4, 17, 19, 20, 21];arrow_forwardCounting hashtags Write Python code to count the frequency of hashtags in a twitter feed. Your code assumes a twitter feed variable tweets exists, which is a list of strings containing tweets. Each element of this list is a single tweet, stored as a string. For example, tweets may look like: tweets = ["Happy #IlliniFriday!", "It is a pretty campus, isn't it, #illini?", "Diving into the last weekend of winter break like... #ILLINI #JoinTheFight", "Are you wearing your Orange and Blue today, #Illini Nation?"] Your code should produce a sorted list of tuples stored in hashtag_counts, where each tuple looks like (hashtag, count), hashtag is a string and count is an integer. The list should be sorted by count in descending order, and if there are hashtags with identical counts, these should be sorted alphabetically, in ascending order, by hashtag. From the above example, our unsorted hashtag_counts might look like: [('#illini', 2), ('#jointhefight', 1),…arrow_forwardWrite the statement that declares and instantiates an array of type double using the identifier temperatures that will hold 30 values. Edit View Insert Format Tools Table 12pt v Paragraph v :arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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