import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Arraz {


    public int sumValuesOfArray(int[] array){
        int sum = 0;
        for (int each:array) {
            sum += each;
        }
        return sum;
    }

    public double sumDoublesOfArray(double[] array){
        double sum = 0;
        for (double each:array) {
            sum += each;
        }
        return sum;
    }

    public int averageOfArray(int[] array) {
        return sumValuesOfArray(array)/array.length;
    }

    public double doubleAverageOfArray(double[] array){
        return sumDoublesOfArray(array)/array.length;
    }

    public boolean containsValue(int[] array, int value){
        for(int each: array){
            if (each == value){
                return true;
            }
        }
        return false;
    }

    public int[] reverseArray(int[] array){
        int[] newArray = new int[array.length];
        int index = 0;
        for (int i = array.length - 1; i >= 0; i--){
            newArray[index] = array[i];
            index++;
        }
        return newArray;
    }

    public OddEven oddEvens(int[] array){
        int evens = 0;
        int odds = 0;
        for(int each: array){
            if(each % 2 ==0){
                evens++;
            } else {
                odds++;
            }
        }
        return new OddEven(odds, evens);
    }

    public int getIndexOf(int[] array, int value){
        for (int i = 0; i < array.length -1; i++){
            if (array[i] == value){
                return i;
            }
        }
        return -1;
    }

    public Integer[] copyArrayByIterator(Integer[] array){
        Integer[] newArray = new Integer[array.length];
        Iterator<Integer> iterator = Arrays.asList(array).iterator();
        int index = 0;
        while(iterator.hasNext()) {
            newArray[index] = iterator.next();
            index++;
        }
        return newArray;
        }

    public int[] copyArrayByLoop(int[] array){
        int[] newArray = new int[array.length];
        int index = 0;
        for(int each:array){
            newArray[index] = each;
            index++;
        }
        return newArray;
    }

    public int[] removeElementFromArray(int[] array, int value){
        int[] newArray = new int[array.length -1];
        int index = 0;
        for (int each:array) {
            if(each!=value){
                newArray[index] =each;
                index++;
            }
        }
        return newArray;
    }

    public int[] insertArrayAt(int[] array, int index, int value){
        int[] newArray = new int[array.length + 1];
        int counter = 0;
        for (int i = 0; i < array.length-1; i++) {
            if (i == index){
                newArray[index] = value;
                counter++;
            }else {
                newArray[counter] = array[i];
                counter++;
            }
        }
        return newArray;
        }

    public MaxMin findMaxMinOfArray(int[] array){
        Arrays.sort(array);
        return new MaxMin(array[array.length - 1], array[0]);
    }

    public Integer[] removeDupesFromArray(Integer[] array){
        Set<Integer> integerSet = new HashSet<>();
        integerSet.addAll(Arrays.asList(array));
        Integer[] integers = new Integer[integerSet.size()];
        return integerSet.toArray(integers);
    }

}
