Solución

@isakidev
·hace 5dTypeScript
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
Respuestas
0

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.
Markdown