Question: Refer to example E demonstrating the filter function on the array Census which contains population data on Canadian cities in the year 2016 and 2019.
Refer to example E demonstrating the filter function on the array Census which contains population data on Canadian cities in the year 2016 and 2019.
a. Write a filter that returns only the elements of Census where the population has decreased between 2016 and 2019.
b. Write filter that is also p assed a minimum and maximum value and returns only those cities with a population with that range. Test on 2 different ranges and make sure you verify the results.
//Example E: filters applied to console.log("Example E: filter functions"); //Filter returns a list of Census entries where the Province is Ontario censusResult1=Census.filter( cityInfo => { return cityInfo.Province == "Ontario" }); console.log("Filtering for Ontario census data: ",censusResult1);
//Filter returns a list of Census entries in a list of provinces censusResult2=Census.filter( (cityInfo,index,self,provinceList=["Manitoba","Alberta","Yukon"]) => { //console.log(cityInfo,index,self,provinceList); //Remove comment to see a full trace of the function return provinceList.indexOf(cityInfo.Province) >=0 }); console.log("Filtering for multiple provinces: ",censusResult2);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
