Question: in javascript! can i please have an explanation if the code as well let arr = [1,2,3].map(YOUR FUNCTION HERE) Note that [1,2,3] is an array

in javascript! can i please have an explanation if the code as well let arr = [1,2,3].map(YOUR FUNCTION HERE) Note that [1,2,3] is an array and map function is defined on the Array object. Read about Array on MDN. Your function should call CourseItem and pass the same keys with different values each time map calls it. The return value of CourseItem should be the return value of your function. After the above line add a console.log(arr) to print the contents of arr Call the status function using the array you created in the code above. For each element of the array pass all the key-value pairs. Again, I will use totally different key-value pairs to test you code. So, don't hardcode any key value pairs (other than year and university, of course). here is the status function code

const course_id = 'CSC441';

const section = 'H001';

const university='usm';

const term = 'spring_semester';

const year = 2021;

function CourseItem(props)

{ var yearPresent=false;

//Check if props is a string then print and return immediately

if(typeof props === "string"){

console.log(props);

return; }

//Check if props is an object

if(typeof props === "object")

{ var keys=Object.keys(props);

for(let i=0;i

{ //check if a key named "year" is present, if present assign true to yearPresent variable

if(keys[i]==="year"){

yearPresent=true;

}

//print all key and values of the props console.log

(keys[i]," : ",props[keys[i]]);

}

//if year is present then return a new object with the year as key and props as object

if(yearPresent){ var year=props["year"];

var newobj={};

newobj[year]=props;

return newobj;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!