Test 15: All tests passed but stuck at test 15. Could anyone identify the issue?
const manifest = { destination: “Watsonville”, hazmat: true };
const normalizeUnits = (manifest) => {
const newManifest = {…manifest};
if(newManifest.unit === ‘lb’){
newManifest.weight = newManifest.weight \* 0.45;
newManifest.unit = 'kg'
}
return newManifest;
};
const validateManifest = (manifest) => {
let result = {};
if(manifest.hasOwnProperty(‘containerId’)){
const key = 'containerId';
if(manifest\[key\] === null || Number.isInteger(manifest\[key\]) && Number(manifest\[key\]) <= 0 || manifest\[key\]?.toString()?.includes('.')){
result\[key\] = 'Invalid';
}
}else {
result\['containerId'\] = 'Missing';
}
if(manifest.hasOwnProperty(‘destination’)){
const key = 'destination';
if(!manifest\[key\]?.toString()?.trim() || Number.isInteger(manifest\[key\])) {
result\[key\] = 'Invalid';
}
} else {
result\['destination'\] = 'Missing';
}
if(manifest.hasOwnProperty(‘weight’)){
const key = 'weight';
if(Number.isNaN(manifest\[key\]) || !Number.isInteger(manifest\[key\]) || Number(manifest\[key\]) < 0){
result\[key\] = 'Invalid';
}
} else {
result\['weight'\] = 'Missing';
}
if(manifest.hasOwnProperty(‘hazmat’)){
const key = 'hazmat';
if(typeof manifest\[key\] !== 'boolean'){
result\[key\] = 'Invalid';
}
} else {
result\['hazmat'\] = 'Missing';
}
if(manifest.hasOwnProperty(‘unit’)){
const key = 'unit';
if(manifest\[key\]?.toLowerCase() !== 'lb' && manifest\[key\]?.toLowerCase() !== 'kg'){
result\[key\] = 'Invalid';
}
} else {
result\['unit'\] = 'Missing';
}
return result;
};
const processManifest = (manifest) => {
if(manifest === null || manifest === undefined) manifest = {};
const isValidate = validateManifest(manifest);
if(Object.values(isValidate).length === 0) {
const normalizedWeight = normalizeUnits(manifest);
console.log(\`Validation success: ${manifest.containerId}\`);
console.log(\`Total weight: ${normalizedWeight.weight} kg\`)
} else {
console.log(\`Validation error: ${manifest.containerId}\`);
console.log(isValidate);
}
};
processManifest(manifest);

