Solución
solution.tsTypeScript
type Gate = "AND" | "OR" | "XOR" | "NAND";
function logicGate(firstValue: boolean, secondValue: boolean, gate: Gate): boolean {
const gates: Record<Gate, (a: boolean, b: boolean) => boolean> = {
"AND": (a, b) => a && b,
"OR": (a, b) => a || b,
"XOR": (a, b) => Boolean(Number(a) ^ Number(b)),
"NAND": (a, b) => !(a && b)
}
return gates[gate](firstValue, secondValue);
}
// No modificar: necesario para evaluar el resultado.
export { logicGate };0respuestas