Khalil Malik Saboor 6 vuotta sitten
vanhempi
commit
5ccf4c57e7

+ 14
- 12
src/main/java/io/zipcoder/ArrayDrills.java Näytä tiedosto

73
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
73
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
74
      */
74
      */
75
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
75
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
76
+        Integer [] myArray = new Integer[2];
76
 
77
 
77
-        Integer newArr [] = {};
78
+        if (input1.length % 2 != 0 && input2.length % 2 != 0){
78
 
79
 
79
-        if(newArr.length % 2 == 0){
80
 
80
 
81
-        } else{
81
+        } else if(input1.length % 2 == 0 && input2.length % 2 == 0){
82
 
82
 
83
         }
83
         }
84
         return null;
84
         return null;
91
      * Return the array which has the largest sum. In event of a tie, return a.
91
      * Return the array which has the largest sum. In event of a tie, return a.
92
      */
92
      */
93
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
93
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
94
-
95
-        int Sum = a[0] + a[1] -b[0]-b[1];
96
-        if (Sum >= 0){
97
-            return a;
98
-
94
+        if (a[0] + a[1] < b[0] + b[1]){
95
+            return b;
99
         }
96
         }
100
-        return b;
97
+        return a;
101
     }
98
     }
102
 
99
 
103
     /**
100
     /**
108
      */
105
      */
109
     public Integer[] midThree(Integer[] nums){
106
     public Integer[] midThree(Integer[] nums){
110
 
107
 
111
-        if(nums.length % 2 == 0){
108
+        Integer [] myArray = new Integer[3];
112
 
109
 
113
-        }
110
+        Integer middle = nums.length/2;
114
 
111
 
115
-        return null;
112
+        myArray[0] = nums[middle-1];
113
+        myArray[1] =  nums[middle];
114
+        myArray[2] = nums[middle+1];
115
+
116
+
117
+     return myArray;
116
     }
118
     }
117
 }
119
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java Näytä tiedosto

179
     public void biggerTwo3(){
179
     public void biggerTwo3(){
180
         Integer[] inputArray1 = {-1 ,20};
180
         Integer[] inputArray1 = {-1 ,20};
181
         Integer[] inputArray2 = {2, 15};
181
         Integer[] inputArray2 = {2, 15};
182
-        Integer[] expected = {1,20};
182
+        Integer[] expected = {-1,20};
183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
184
         Assert.assertArrayEquals(expected, actual);
184
         Assert.assertArrayEquals(expected, actual);
185
     }
185
     }

BIN
target/classes/io/zipcoder/ArrayDrills.class Näytä tiedosto


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class Näytä tiedosto