Pares del principio y del final
Empareja el primer número entero de un arreglo con el último, el segundo con el penúltimo y así sucesivamente.
Ejemplos
Program.Pairs(new[] { 1, 1, 1, 1, 7, 2, 3, 2 }) // new[] { new[] { 1, 2 }, new[] { 1, 3 }, new[] { 1, 2 }, new[] { 1, 7 } }
Program.Pairs(new[] { 5, 4, 4, 6, 6, 6, 4 }) // new[] { new[] { 5, 4 }, new[] { 4, 6 }, new[] { 4, 6 }, new[] { 6, 6 } }
Program.Pairs(new[] { 1, 2, 3, 4, 5, 6, 7 }) // new[] { new[] { 1, 7 }, new[] { 2, 6 }, new[] { 3, 5 }, new[] { 4, 4 } }
Program.Pairs(new[] { 1, 2, 3, 4, 5, 6 }) // new[] { new[] { 1, 6 }, new[] { 2, 5 }, new[] { 3, 4 } }
Program.Pairs(new[] { 5, 9, 8, 1, 2 }) // new[] { new[] { 5, 2 }, new[] { 9, 1 }, new[] { 8, 8 } }
Program.Pairs(new int[] { }) // new int[0][]Notas
- Si el arreglo tiene una longitud impar, empareja el valor central consigo mismo.
- Devuelve un arreglo vacío si la entrada está vacía.