Tell us what’s happening:
El codigo supero el 99 por ciento de las pruebas, excepto la numero 15 .. no logro superarla, investigue pregunte y aun asi no pude lograr pasar la prueba .
si alguien pudo pasar la prueba o entendio el problema seria de gran ayuda enterder por que funciona y por que no funciono antes! gracias
Your code so far
function normalizeUnits(manifest){
const copiManifest = {...manifest};
if(manifest.unit === "lb"){
const kilogramos = manifest.weight * 0.45;
copiManifest.weight = kilogramos;
copiManifest.unit = "kg";
};
return copiManifest;
};
function validateManifest(manifest){
const errors = {};
const tipes = ["containerId", "destination", "weight", "unit", "hazmat"];
tipes.forEach((value)=>{
if(!(value in manifest) || manifest[value] === undefined){
errors[value] = "Missing";
return
}
const values = manifest[value]
switch(value){
case "containerId":
if(!Number.isInteger(values) || values <= 0 ) errors[value] = "Invalid";
break;
case "destination":
if(typeof values !== "string" || values.trim().length === 0) errors[value] = "Invalid";
break;
case "weight":
if(typeof values !== "number" || Number.isNaN(values) || values < 0) errors[value] = "Invalid";
break;
case "unit":
if(values !== "kg" && values !== "lb") errors[value] = "Invalid";
break;
case "hazmat":
if(typeof values !== "boolean") errors[value] = "Invalid"
break;
}
});
return errors;
};
function processManifest(manifest){
const errors = validateManifest(manifest);
if(Object.keys(errors).length === 0) {
console.log(`Validation success: ${manifest.containerId}`)
const normalized = normalizeUnits(manifest);
console.log(`Total weight: ${normalized.weight} kg`)
}else{
console.log(`Validation error: ${manifest.containerId}`)
console.log(errors);
};
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator