Challenges/arrayShift/arrayShift/Program.cs
/// <summary>
/// Insert a number into the middle of an array
/// </summary>
/// <param name="array">Given array to insert number</param>
/// <param name="middleNum">Number to insert into array</param>
/// <returns></returns>
Insert a number into the middle of an array
Insert a number into the middle of an array
public static int[] ArrayShift(int[] array, int middleNum)
        {
            int[] newArray = new int[array.Length + 1];
            int counter = 0;
            decimal midIndex = Math.Ceiling((decimal)(array.Length) / 2);
            for (int i = 0; i < newArray.Length; i++)
            {
                if (midIndex == i)
                {
                    newArray[i] = middleNum;
                }
                else
                {
                    newArray[i] = array[counter++];
                }
            }
            return newArray;
        }
public static int [ ] ArrayShift ( int [ ] array , int middleNum ) { int [ ] newArray = new int [ array . Length + 1 ] ; int counter = 0 ; decimal midIndex = Math . Ceiling ( ( decimal ) ( array . Length ) / 2 ) ; for ( int i = 0 ; i < newArray . Length ; i ++ ) { if ( midIndex == i ) { newArray [ i ] = middleNum ; } else { newArray [ i ] = array [ counter ++ ] ; } } return newArray ; }
Insert a number into the middle of an array
Insert a number into the middle of an array
//instantiate a new array of input array size +1 //instatiate counter //using decimal and Math.Ceiling allows the correct middle index to be located  //with an unvenen index length
None
array
int[]
Given array to insert number
Given array to insert number
middleNum
int
Number to insert into array
Number to insert into array