Solución

@erikbo9·hace 3dTypeScript
solution.tsTypeScript
function wordInMatrix(matrix: string[][], word: string): boolean {
  // verificar verticales
  if (matrix.length > 1) {
    for (let j = 0; j < matrix[0].length; j++) {
      let resultadoVertical = true;

      for (let i = 0; i < word.length; i++) {
        if (!(matrix[i][j] === word[i])) {
          resultadoVertical = false;
        }
      }

      if (resultadoVertical) return true;
    }
  }

  //Verificar Horizontales
  for (let i = 0; i < matrix.length; i++) {
    let resultadoHorizontal = true;

    for (const [index, l] of matrix[i].entries()) {
      if (!(l === word[index])) {
        resultadoHorizontal = false;
      }
    }

    if (resultadoHorizontal) return true;
  }

  return false;
}

export { wordInMatrix };
0respuestas
Respuestas

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.