Question

In: Computer Science

Write a function that takes an Array of cases, as well as an FSA String value....

Write a function that takes an Array of cases, as well as an FSA String value.

This Case data is an Array where each item in the Array is a custom Case Object. The Array is really [case1, case2, case3, ...], and each Case Object has the following structure:
  {
     "Age Group": "40 to 49 Years",
     "Neighbourhood Name": "Annex",
     "Outcome": "RESOLVED",
     "Client Gender": "FEMALE",
     "Classification": "CONFIRMED",
     "FSA": "M5R",
     "Currently Hospitalized": "No",
     "Episode Date": "2020-09-12",
     "Assigned_ID": 17712,
     "Outbreak Associated": "Sporadic",
     "Ever Intubated": "No",
     "Reported Date": "2020-09-16",
     "Currently in ICU": "No",
     "Source of Infection": "Healthcare",
     "_id": 161028,
     "Ever in ICU": "No",
     "Ever Hospitalized": "No",
      "Currently Intubated": "No"
}


An FSA if a forward sortation area (the first 3 characters in a Canadian postal code):
https://en.wikipedia.org/wiki/Postal_codes_in_Canada#Forward_sortation_areas
Return a new Array with only those case Objects that contain the given fsa value.
You should support the FSA value being CAPITALIZED or lowercase, as well as deal with any case Objects that don't have an FSA value (e.g., null/undefined)

In your solution, make use of the following:

  - create an empty array
- use a for...of loop to loop over all Objects in cases
  - if a case includes the given fsa, add the case Object to the empty Array

Your function should return the newly created Array.
function getCasesByFSA(cases, fsa) {}

Solutions

Expert Solution

Hello! :)

Here's a documented code to solve the assignment:

/**
 * Returns a new Array with only those case Objects that contain the given fsa value.
 * @param cases An array of case Objects.
 * @param fsa A string representing the FSA(forward sortatin area).
 * @returns A newly created array of case Objects that contain the matching fsa value.
 */
function getcasesByFSA(cases, fsa) {

    // create an empty array
    const result = [];

    // use a for...of loop to loop over all Objects in cases
    for(eachcase of cases) {

        if(
            eachcase['FSA']                                     // if a case includes the given fsa
            &&                                                  // and
            fsa.toUpperCase() === eachcase['FSA'].toUpperCase() // the uppercase FSA value of the case Object and the passed fsa values match
        ) {
            // add the case Object to the empty Array
            result.push(eachcase);
        }

    }

    return result;
}

Hope this helps! :)


Related Solutions

Sort a string array by frequency given an array of string write a function that will...
Sort a string array by frequency given an array of string write a function that will return an array that is sorted by frequency example {"hello","hola","hello","hello","ciao","hola","hola","hola"} returned array should be {"hola","hello","ciao"}
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write a java method that takes a string and returns an array of int that contains...
Write a java method that takes a string and returns an array of int that contains the corresponding alphabetic order of each letter in the received string: An illustration: the method takes: "Sara" the method returns: {4,1,3,2} another illustration: the method takes: "hey" the method returns: {2,1,3}
Write a Java method that takes an array of char and a String as input parameters...
Write a Java method that takes an array of char and a String as input parameters and and returns an boolean. The method returns true if we can find the input string inside the array by starting at any position of the array and reading either forwards or backwards.
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
Write a function in C# that takes an array of double as the parameter, and return...
Write a function in C# that takes an array of double as the parameter, and return the average
C programming Write a function called string in() that takes two string pointers as arguments. If...
C programming Write a function called string in() that takes two string pointers as arguments. If the second string is contained in the first string, have the function return the address at which the contained string begins. For instance, string in(“hats”, “at”) would return the address of the a in hats. Otherwise, have the function return the null pointer. Test the function in a complete program that uses a loop to provide input values for feeding to the function.
Write a function in C that takes one argument, an array of 50 elements. Your function...
Write a function in C that takes one argument, an array of 50 elements. Your function should print out the index and value of the smallest element in the array.
Write a function called swapElements to swap two elements in a character array. This function takes...
Write a function called swapElements to swap two elements in a character array. This function takes two parameters, a character array and input file. The function should read two numbers from a file and it swap the elements stored in the indices read. please code in c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT