Develop the booleanize
function so it transforms an object's properties based on the criteria listed (see requirements below). This function will loop over each property in the object and apply certain transformations to its values, while also handling edge cases related to property names.
function booleanize(obj)
- obj: An object with any number of properties.
- Transform any value of zero (
0
) into the booleanfalse
. - Transform any value of one (
1
) into the booleantrue
. - If a value is
null
, delete the entire key-value pair from the object. - If any property name exceeds 9 characters, return the string
"shorten all prop names to 9 chars or less"
.
- Ensure no unintended changes are made to the object's structure or other properties.
let obj = {
keyZero: 0,
keyOne: 1,
keyNull: null,
keyTwo: 2
};
let result = booleanize(obj);
console.log(result);
Expected Output:
{
keyZero: false,
keyOne: true,
keyTwo: 2
}
let obj = {
veryLongPropertyName: 0,
keyOne: 1
};
let result = booleanize(obj);
console.log(result);
Expected Output:
"shorten all prop names to 9 chars or less"