Question

In: Computer Science

Part I: transformCase(original) and transformCases(cases) * * Write functions to transform COVID case data into a...

Part I: transformCase(original) and transformCases(cases)
*
* Write functions to transform COVID case data into a new Object format.
*
* The `transformCase(original)` function takes an Object like so:
*
* {
* "Age Group": "20 to 29 Years",
* "Neighbourhood Name": "Humewood-Cedarvale",
* "Outcome": "ACTIVE",
* "Client Gender": "FEMALE",
* "Classification": "CONFIRMED",
* "FSA": "M6C",
* "Currently Hospitalized": "No",
* "Episode Date": "2020-09-11",
* "Assigned_ID": 17704,
* "Outbreak Associated": "Sporadic",
* "Ever Intubated": "No",
* "Reported Date": "2020-09-18",
* "Currently in ICU": "No",
* "Source of Infection": "Close contact",
* "_id": 161020,
* "Ever in ICU": "No",
* "Ever Hospitalized": "No",
* "Currently Intubated": "No"
* },
*
* And transforms the data in the `original` case Object into a new Object
* that looks like this (see comments on right-hand side with details):
*
* {
* id: 161020, // rename _id to id
* isActive: true, // true if Outcome is "ACTIVE", false otherwise
* neighbourhood: "Humewood-Cedarvale", // rename Neighbourhood Name to neighbourhood
* hospitalInfo: {
* current: {
* hospitalized: false, // true if Currently Hospitalized is Yes, false otherwise
* inICU: false // true if Currently In ICU is Yes, false otherwise
* intubated: false, // true if Currently Intubated is Yes, false otherwise
* },
* historical: {
* hospitalized: false, // true if Ever Hospitalized is Yes, false otherwise
* inICU: false // true if Ever In ICU is Yes, false otherwise
* intubated: false, // true if Ever Intubated is Yes, false otherwise
* }
* }
* }
******************************************************************************/
function transformCase(original) {}

/*******************************************************************************
Part II: transformCases(cases) with iteration
*
* The `transformCases(cases)` (NOTE: transformCase singular vs. transformCases plural)
* takes an Array of case Objects, and returns a new Array of transformed Objects,
* calling transformCase() on each.
*
* In your solution, make use of the following:
*
* - create a new empty Array to hold all the transformed cases
* - use a for-loop or .forEach() method to loop over all Objects in the of the cases Array
* - pass each case Object to your transformCase() function to get a new Object
* - add the new Object to your new array
* - return the new array with all the transformed Objects
******************************************************************************/
function transformCases(cases) {}

/*******************************************************************************
Part III: transformCases(cases) with .map()
*
* Rewrite your transformCases() function a second time using the Array .map() method
* see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
*
* In your solution, make use of the following:
*
* - use the .map() method of the cases Array to create a new Array
* - In the .map() method's function, call your transformCase() function
* - return the Array created by the .map() method
******************************************************************************/
function transformCases2(cases) {}

Solutions

Expert Solution

Hello Champ!

Here is the solution for the question -

Every step is self explanatory, if you face any issue, feel free to ask.

Part-1: transformCase() Function -

function transformCase(o)
{ 
  var c = new Object();
  c.id=o["_id"];
  c.isActive = (o["Outcome"]==="ACTIVE")?(true):(false);        
  c.neighbourhood = o["Neighbourhood Name"];
  
  var curr = new Object();
      curr.hospitalized = (o["Currently Hospitalized"]==="No")?false:true;
      curr.inICU = (o["Currently in ICU"]==="No")?false:true;
      curr.intubated = (o["Currently Intubated"]==="No")?false:true;
  
  var histo = new Object();
      histo.hospitalized=(o["Ever Hospitalized"]==="No")?false:true;    
      histo.inICU=(o["Ever in ICU"]==="No")?false:true;
      histo.intubated= (o["Ever Intubated"]==="No")?false:true;
  
  var hospitalinfo = new Object();
  hospitalinfo.historical = histo;
  hospitalinfo.current = curr;

  c.hospitalInfo = hospitalinfo;
  return(c);
}

Part-2: transformCases() Function using Iteration -

function transformCases(cases){
    var tranformed_cases = [];
    cases.forEach(function f(item){
        var new_case = transformCase(item);
        tranformed_cases.push(new_case);
    });
    return tranformed_cases;
}

Part-3: transformCase() Function using map function -

function transformCases_withmap(cases){
    cases.map(function f(item){
        return transformCase(item);
    });
    return cases;
}

Hope It Helps!

Don't forget to Like ;)


Related Solutions

why is it so challenging to capture data changes as part of an extract, transform, and...
why is it so challenging to capture data changes as part of an extract, transform, and load (ETL) process? WHAT ARE SOME METHODS THAT CAN BE USED TO CAPTURE INCREMENTAL DATA CHANGES And are there any drawbacks to these methods? (sorry for the caps)
Using the template given in ParallelMergeSort.c write the functions to divide the original array into equal...
Using the template given in ParallelMergeSort.c write the functions to divide the original array into equal fractions given the number of threads and perform Parallel MergeSort pThreads. Your algorithm should work for 2 threads. ParallelMergeSort.c #include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #define SIZE 100 int array[SIZE]; void fillArrayWithRandomNumbers(int arr[SIZE]) { for(int i = 0; i<SIZE; i++) array[i] = rand()%100; } void printArray(int arr[SIZE]) { for(int i = 0; i<SIZE; i++) printf("%5d", arr[i]); printf("\n"); } typedef struct...
Using the template given in ParallelMergeSort.c write the functions to divide the original array into equal...
Using the template given in ParallelMergeSort.c write the functions to divide the original array into equal fractions given the number of threads and perform Parallel MergeSort pThreads. Your algorithm should work for 2 threads. ParallelMergeSort.c #include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #define SIZE 100 int array[SIZE]; void fillArrayWithRandomNumbers(int arr[SIZE]) { for(int i = 0; i<SIZE; i++) array[i] = rand()%100; } void printArray(int arr[SIZE]) { for(int i = 0; i<SIZE; i++) printf("%5d", arr[i]); printf("\n"); } typedef struct...
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft...
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft and dft. Applied to discrete signals. If you can with an example.Thank you!!
A4. The data below shows the weekly cases of Covid-19 for Ghana as at 19th June...
A4. The data below shows the weekly cases of Covid-19 for Ghana as at 19th June 2020 since the first case was recorded on 2nd March 2020(Source: WHO). 2571 1473 1582 817 956 2439 1017 920 513 263 174 72 121 11 It is being argued on public airwaves that, the average weekly cases in Ghana is more than 500. By testing the claim of what is being said on airwaves using the Sign Test, compute the significance probability of...
how data will transform business ? please write an essay for about 450 words
how data will transform business ? please write an essay for about 450 words
Read the case study below and write an original response. Your response should be a minimum...
Read the case study below and write an original response. Your response should be a minimum of 500 words in length in order to be eligible for full credit. John, a 30-year-old male, married and the father of a two-year-old daughter, is diagnosed as brain dead after a motorcycle accident. Mary, his wife, arrives at the hospital and signs the papers for multiple organ procurement and makes one additional request—that her deceased husband’s sperm be obtained and frozen. She intends...
Case Study Project – PART I Overview The purpose of the case study project is to...
Case Study Project – PART I Overview The purpose of the case study project is to get you acquainted with the security challenges of a real, complex, messy software product. In class, you will be learning about security ideals,   and best practices. In the case study, you will see how those ideals are applied, or not applied. This case study is designed to help you in two key ways: investigation and co-authorship. The investigative part of this project is to...
UpCo’s inventory data is as follows: Cases on hand Cost per case Market per case 1....
UpCo’s inventory data is as follows: Cases on hand Cost per case Market per case 1. Garden Supplies a. Snail Bait 35 $80 $75 b. Isotox 12 20 23 c. Shovels 20 100 99 2. Hardware a. Screws 20 $80 $96 b. Brackets 2 35 31 c. Nails 8 12 12 3. Paint a. Enamel -1 gal. 22 $120 $118 b. Spray Cans 15 45 54 c. Misc. Brushes 4 30 38 Calculate LCM by group: $10,082 $9,994 $10,378 $10,517...
The below contains the actual data on COVID-19 cases in Ghana from 1st April, 2020 to...
The below contains the actual data on COVID-19 cases in Ghana from 1st April, 2020 to 25th May, 2020 as presented by the Ghana Health Service. Use the information provided to answer the following questions: Construct a graph to show the trends of the COVID-19 confirmed cases and fatalities in Ghana, and speculate on the factors that might have influenced these trend Date Total confirmed Death Recoveries Test 1-Apr 195 5 3 12046 2-Apr 204 5 3 12046 3-Apr 205...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT