So this is the prompt that I am currently doing:
Define a function mapObject that accepts the same arguments as map except it works for Objects. You must then use mapObject and use it on the input given below. Then define a callback function, format, to be passed into mapObject so that we get the output below. format should receive two arguments, the key and value.
The input is an object, output is object with formatted values. You can hard code "biography" in format; Do not hard code anything else Do not create any other functions
so this is the example of the object (no known variable name).
example:
console.log(mapObject(input, format));
Input:
{
firstName: "James",
lastName: "Hu",
gender: "Male",
biography: "Oh hey, I'm just a guy"
}
Output:
{
firstName: "JAMES",
lastName: "HU",
gender: "MALE",
biography: "oh hey, i'm just a guy"
}
my current solution is as follows:
var mapObject = function(object, callback) {
var newObject = {};
for (let key in object) {
newObject[key] = callback(key, object[key]);
}
return newObject;
};
var format = function(key, value) {
if (key === "biography") {
return value.toLowerCase();
}
else {
return value.toUpperCase();
}
};
Everytime I run the code, I return, cannot read property should of undefined. Can someone help me to figure out what I am doing wrong?