Solución
solution.tsTypeScript
function intercalateArrays(arrayA: unknown[], arrayB: unknown[]): unknown[] {
// If either array is empty, return the other
if (arrayA.length === 0) return arrayB
if (arrayB.length === 0) return arrayA
// Determine the number of iterations needed
const maxLengthArr = Math.max(arrayA.length, arrayB.length)
// Return a new list with values interleaved, excluding null and undefined
return Array.from({ length: maxLengthArr })
.flatMap((_, i) => [arrayA[i], arrayB[i]])
.filter(v => v != null)
}
// No modificar: necesario para evaluar el resultado.
export { intercalateArrays };0respuestas