import java.util.*;

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; i++) {
            if (counter == index){
                newArray[counter] = value;
                counter++;
                i--;
            }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 LinkedHashSet<>(Arrays.asList(array));
        return integerSet.toArray(new Integer[0]);
    }

    public Double find2ndLargestValueFromArray(Double[] array){
        Set<Double> set = new TreeSet<>(Arrays.asList(array));
        Double[] newArray = set.toArray(new Double[0]);
        return newArray[newArray.length - 2];
    }

    public List<Integer> makeMeAnArrayListFromArray(Integer[] array){
       return Arrays.asList(array);
    }

    public Integer[] makeMeAnArrayFromArrayList(List<Integer> list){
        return list.toArray(new Integer[0]);
    }

    public boolean check2ArraysForEqual(int[] array1, int[] array2){
        return Arrays.equals(array1, array2);
    }

    public double averageArrayWithoutMaxMin(int[] array){
        MaxMin maxMin = findMaxMinOfArray(array);
        int[] noMax = removeElementFromArray(array, maxMin.getMax());
        int[] noMaxMin = removeElementFromArray(noMax, maxMin.getMin());
        return averageOfArray(noMaxMin);
    }

    public boolean arrayHas65and77(Integer[] array){
        List<Integer> list = Arrays.asList(array);
            if(list.contains(65) && list.contains(77)){
                return true;
            }else{return false;}
    }

    public boolean theTotalOfTenIs30(Integer[] array){
        int sum10 = 0;
        for (Integer each:array){
            if(each == 10){
                sum10 += each;
                if(sum10 == 30){
                    return true;
                }
            }
        }
        return false;
    }

    public Integer[] min2Array(Integer[] array){
        Set<Integer> minSet = new TreeSet<>(Arrays.asList(array));
        return Arrays.copyOfRange(minSet.toArray(new Integer[0]), 0, 2);
    }

    public int[] reverseCopy(int[] array){
       return reverseArray(array);
    }

    public int[] removeLastItemCopy(int[] array){
        return removeElementFromArray(array, array[array.length-1]);
    }

    public int[] removeFirstItemCopy(int[] array){
        return removeElementFromArray(array, array[0]);
    }

    public int[] insertStartCopy(int[] array, int value){
        return insertArrayAt(array, 0, value);
    }

    public Integer[] insertEndCopy(Integer[] array, int value){
        List<Integer> list = new ArrayList<>(Arrays.asList(array));
        list.add(value);
        return list.toArray(new Integer[0]);
    }
}
