Solución

@josemcarrizosa98_f7e20d3d
·24/3/2026TypeScript
solution.tsTypeScript
function intersection(firstArray: number[], secondArray: number[]): number[] {

  const rightNumbersSet : Set<number> = new Set();

  // using a set to access the right values with a key  
  secondArray.forEach( rightValue => rightNumbersSet.add(rightValue))
  
  
  const numbersInIntersection: Set<number> = new Set();
  // looping over the firstArray to get the left order of appearance
  firstArray.forEach( leftValue => {
     // checking for a match 
     if(rightNumbersSet.has(leftValue)){
          numbersInIntersection.add(leftValue)
     }
  })  

  return [...numbersInIntersection]
}

// No modificar: necesario para evaluar el resultado.
export { intersection };
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