Solución
solution.tsTypeScript
function logicGate(firstValue: boolean, secondValue: boolean, gate: "AND" | "OR" | "XOR" | "NAND"): boolean {
const OPERATORS = {
'AND': (firstValue: boolean,secondValue: boolean) => firstValue && secondValue,
'OR': (firstValue: boolean, secondValue: boolean) => firstValue || secondValue,
'XOR': (firstValue: boolean, secondValue: boolean) => firstValue !== secondValue,
'NAND': (firstValue: boolean, secondValue: boolean) => !(firstValue && secondValue)
}
return OPERATORS[gate](firstValue, secondValue)
}
// No modificar: necesario para evaluar el resultado.
export { logicGate };0respuestas