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

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 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.
Python please Write a function that takes a string as an argument checks whether it is...
Python please Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and...
in c++ Write a function that takes a C string as an input parameter and reverses...
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 function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Write a C function str_to_float() that takes a numeric string as input and converts it to...
Write a C function str_to_float() that takes a numeric string as input and converts it to a floating point number. The function should return the floating point number by reference. If the conversion is successful, the function should return 0, and -1 otherwise (e.g. the string does not contain a valid number). The prototype of the function is given below int str_to_float(char * str, float * number);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT