mystery8 methods

public static int[] duplicateAll(int[] arr)
{
    int[] newArr = new int[arr.length * 2];
    duplicateAll(arr, newArr, 0);
    return newArr;
}

private static void duplicateAll(int[] oldArr, int[] newArr, int oldIndex)
{
    if(oldIndex >= oldArr.length)
        return;
    
    newArr[oldIndex] = oldArr[oldIndex];
    newArr[oldArr.length + oldIndex] = oldArr[oldIndex];
    
    duplicateAll(oldArr, newArr, oldIndex + 1);
}

The method returns a new array in which the element in the old array appear twice.

duplicateAll(new int[]{1, 2, 3, 4}) returns [1, 2, 3, 4, 1, 2, 3, 4]

mystery7 solution
Exercises
All solutions