Procházet zdrojové kódy

Merge 33c1a242b71508b325a9c0ff1c4f91cf4557ae05 into b2e20fd406b12d4908e4fb952d821a476dd96c45

Haysel Giovanni Santiago před 6 roky
rodič
revize
a403b2e4e2
No account linked to committer's email

+ 16
- 0
.idea/compiler.xml Zobrazit soubor

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <annotationProcessing>
5
+      <profile name="Maven default annotation processors profile" enabled="true">
6
+        <sourceOutputDir name="target/generated-sources/annotations" />
7
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8
+        <outputRelativeToContentRoot value="true" />
9
+        <module name="FundamentalDrills-Part1" />
10
+      </profile>
11
+    </annotationProcessing>
12
+    <bytecodeTargetLevel>
13
+      <module name="FundamentalDrills-Part1" target="1.5" />
14
+    </bytecodeTargetLevel>
15
+  </component>
16
+</project>

+ 13
- 0
.idea/misc.xml Zobrazit soubor

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="MavenProjectsManager">
4
+    <option name="originalFiles">
5
+      <list>
6
+        <option value="$PROJECT_DIR$/pom.xml" />
7
+      </list>
8
+    </option>
9
+  </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" project-jdk-name="9.0" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
12
+  </component>
13
+</project>

+ 8
- 0
.idea/modules.xml Zobrazit soubor

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/FundamentalDrills-Part1.iml" filepath="$PROJECT_DIR$/FundamentalDrills-Part1.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs.xml Zobrazit soubor

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 16
- 0
FundamentalDrills-Part1.iml Zobrazit soubor

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 44
- 12
src/main/java/io/zipcoder/ArrayDrills.java Zobrazit soubor

@@ -10,7 +10,7 @@ public class ArrayDrills {
10 10
      *           firstLast(6, [1,2,3]); // Should return false
11 11
      */
12 12
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
13
+        return (input[0] == value || input[input.length-1] == value);
14 14
     }
15 15
 
16 16
     /**
@@ -19,10 +19,9 @@ public class ArrayDrills {
19 19
      *           sameFirstLast([1,2,1]); // Should return true
20 20
      */
21 21
     public Boolean sameFirstLast(Integer[] input){
22
-        return null;
22
+    return (input.length >= 1 && input[0] == input[input.length-1]);
23 23
     }
24 24
 
25
-
26 25
     /**
27 26
      * Given 2 arrays of ints, a and b, return true if they have the same first element or they have the same last element.
28 27
      * Both arrays will be length 1 or more.
@@ -30,7 +29,7 @@ public class ArrayDrills {
30 29
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 30
      */
32 31
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
32
+        return (input1[0] == input2[0] || input1[input1.length-1] == input2[input2.length-1]);
34 33
     }
35 34
 
36 35
     /**
@@ -38,8 +37,10 @@ public class ArrayDrills {
38 37
      * example : rotateLeft([1, 2, 3]); // Should return [2,3,1]
39 38
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 39
      */
41
-    public Integer[] rotateLeft(Integer[] input){
42
-        return null;
40
+    public Integer[] rotateLeft(Integer[] input) {
41
+
42
+       Integer[] rotating = {input[1], input[2], input[0]};
43
+        return rotating;
43 44
     }
44 45
 
45 46
 
@@ -50,8 +51,18 @@ public class ArrayDrills {
50 51
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 52
      */
52 53
     public Integer[] maxValue(Integer[] input){
53
-        return null;
54
+    Integer maxValue = input[0];
55
+    for(Integer i = 0; i< input.length; i++) {
56
+        if (input[i] > maxValue) {
57
+            maxValue = input[i];
58
+        }
59
+    }
60
+    Integer[]outPut = new Integer[input.length];
61
+    for(int j=0; j<input.length; j++) {
62
+        outPut[j]=maxValue;
54 63
     }
64
+    return outPut;
65
+}
55 66
 
56 67
 
57 68
     /**
@@ -60,18 +71,33 @@ public class ArrayDrills {
60 71
      * example : middleWay([1, 2, 3], [4,5,6,2]); // Should return [2,11]
61 72
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 73
      */
63
-    public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
74
+    public Integer[] middleWay(Integer[] input1, Integer[] input2) {
75
+        Integer[] newInput = new Integer[2];
76
+        if(input1.length % 2 == 0) {
77
+            newInput[0] = (input1.length / 2) + (input1.length / 2-1);
78
+        } else if (input1.length % 2 != 0){
79
+            newInput[0] = input1[input1.length / 2];
80
+        }
81
+        if (input2.length % 2 == 0) {
82
+            newInput[1] = ((input2[input2.length / 2]) + (input2[input2.length / 2 - 1]));
83
+        }
84
+        else if (input2.length % 2 != 0) {
85
+            newInput[1] = input2[input2.length / 2];
86
+        }
87
+        return newInput;
65 88
     }
66 89
 
67
-
68 90
     /**
69 91
      * Start with 2 int arrays, a and b, each length 2.
70 92
      * Consider the sum of the values in each array.
71 93
      * Return the array which has the largest sum. In event of a tie, return a.
72 94
      */
73 95
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
96
+        int sumA = a[0] + a[1];
97
+        int sumB =  b[0] + b[1];
98
+        if (sumA > sumB)
99
+            return a;
100
+            return b;
75 101
     }
76 102
 
77 103
     /**
@@ -81,6 +107,12 @@ public class ArrayDrills {
81 107
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 108
      */
83 109
     public Integer[] midThree(Integer[] nums){
84
-        return null;
110
+
111
+        Integer[] halfArray = new Integer[3];
112
+        Integer half = (nums.length) / 2;
113
+        halfArray[0] = nums[half-1];
114
+        halfArray[1] = nums[half];
115
+        halfArray[2] = nums[half+1];
116
+        return halfArray;
85 117
     }
86 118
 }

+ 2
- 2
src/test/java/io/zipcoder/ArrayDrillsTest.java Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder;
2 2
 
3
-import com.sun.tools.corba.se.idl.InterfaceGen;
3
+
4 4
 import org.junit.Assert;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;
@@ -177,7 +177,7 @@ public class ArrayDrillsTest {
177 177
 
178 178
     @Test
179 179
     public void biggerTwo3(){
180
-        Integer[] inputArray1 = {-1 ,20};
180
+        Integer[] inputArray1 = {1 ,20};
181 181
         Integer[] inputArray2 = {2, 15};
182 182
         Integer[] expected = {1,20};
183 183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);

binární
target/classes/io/zipcoder/ArrayDrills.class Zobrazit soubor


binární
target/test-classes/io/zipcoder/ArrayDrillsTest.class Zobrazit soubor