12 May 2017

Replace Middle

My solution:
int[] replaceMiddle(int[] arr) 
{
    return arr.Length % 2 == 1
                ? arr
                : arr.Select((i, i1) => i1 != arr.Length / 2 - 1 ? i : arr[arr.Length / 2 - 1] + arr[arr.Length / 2])
                    .Where((i, i1) => i1 != arr.Length / 2)
                    .ToArray();
}

Previous Next