Solución
solution.tsTypeScript
function swapPairs(nums: number[]): number[] {
let newArray = []
for (let i = 0; i < nums.length - 1; i += 2) {
newArray.push(nums[i+1])
newArray.push(nums[i])
}
if(nums.length % 2 != 0) newArray.push(nums.length)
return newArray;
}
// No modificar: necesario para evaluar el resultado.
export { swapPairs };0respuestas