Procházet zdrojové kódy

Merge b03f8f4a055ffb66886bfa40c53473877c46b892 into b2e20fd406b12d4908e4fb952d821a476dd96c45

okmurphy před 6 roky
rodič
revize
ee63d51b7c
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_8" project-jdk-name="1.8" 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>

+ 122
- 53
src/main/java/io/zipcoder/ArrayDrills.java Zobrazit soubor

@@ -1,5 +1,7 @@
1 1
 package io.zipcoder;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 public class ArrayDrills {
4 6
 
5 7
 
@@ -7,19 +9,32 @@ public class ArrayDrills {
7 9
      * Given an array of ints, return true if value appears as either the first or last element in the array.
8 10
      * The array will be length 1 or more.
9 11
      * example : firstLast(6, [1,2,6); // Should return true
10
-     *           firstLast(6, [1,2,3]); // Should return false
12
+     * firstLast(6, [1,2,3]); // Should return false
11 13
      */
12
-    public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
14
+    public Boolean firstLast(Integer value, Integer[] input) {
15
+        Integer number = value;
16
+        Integer[] enter = input;
17
+        Integer last = enter[enter.length - 1];
18
+        if (value.equals(enter[0]) || value.equals(last)) {
19
+            return true;
20
+        }
21
+
22
+        return false;
14 23
     }
15 24
 
16 25
     /**
17 26
      * Given an array of ints, return true if the array is length 1 or more, and the first element and the last element are equal.
18 27
      * example : sameFirstLast([1,2,3]); // Should return false
19
-     *           sameFirstLast([1,2,1]); // Should return true
28
+     * sameFirstLast([1,2,1]); // Should return true
20 29
      */
21
-    public Boolean sameFirstLast(Integer[] input){
22
-        return null;
30
+    public Boolean sameFirstLast(Integer[] input) {
31
+        Integer[] enter = input;
32
+        Integer last = enter[enter.length - 1];
33
+        if (enter[0] == last) {
34
+
35
+            return true;
36
+        }
37
+        return false;
23 38
     }
24 39
 
25 40
 
@@ -27,60 +42,114 @@ public class ArrayDrills {
27 42
      * 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 43
      * Both arrays will be length 1 or more.
29 44
      * example : commonEnd([1, 2, 3], [7, 3]); // Should return true
30
-     *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
45
+     * commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 46
      */
32
-    public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
34
-    }
47
+    public Boolean commonEnd(Integer[] input1, Integer[] input2) {
48
+        Integer[] a = input1;
49
+        Integer[] b = input2;
50
+        Integer lasta = a[a.length - 1];
51
+        Integer lastb = b[b.length - 1];
35 52
 
36
-    /**
37
-     * Given an array of ints, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}.
38
-     * example : rotateLeft([1, 2, 3]); // Should return [2,3,1]
39
-     *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40
-     */
41
-    public Integer[] rotateLeft(Integer[] input){
42
-        return null;
43
-    }
53
+        if (a[0] == b[0]) {
54
+            return true;
55
+        }
56
+               else if (lasta == lastb) {
57
+                    return true;
58
+                }
44 59
 
60
+                    return false;
61
+            }
45 62
 
46
-    /**
47
-     * Given an array of ints, figure out which is element in the array is largest,
48
-     * and set all the other elements to be that value. Return the changed array.
49
-     * example : maxValue([1, 2, 3]); // Should return [3,3,3]
50
-     *           maxValue([5, 11, 9]); // Should return [11,11,11]
51
-     */
52
-    public Integer[] maxValue(Integer[] input){
53
-        return null;
54
-    }
55 63
 
56 64
 
57
-    /**
58
-     * Given 2 int arrays, a and b, return a new array length 2 containing their middle elements, if length is odd.
59
-     * If the array length is even the sum of the middle 2 elements in the array.
60
-     * example : middleWay([1, 2, 3], [4,5,6,2]); // Should return [2,11]
61
-     *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62
-     */
63
-    public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
65
-    }
66 65
 
66
+        /**
67
+         * Given an array of ints, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}.
68
+         * example : rotateLeft([1, 2, 3]); // Should return [2,3,1]
69
+         *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
70
+         */
67 71
 
68
-    /**
69
-     * Start with 2 int arrays, a and b, each length 2.
70
-     * Consider the sum of the values in each array.
71
-     * Return the array which has the largest sum. In event of a tie, return a.
72
-     */
73
-    public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
75
-    }
72
+        public Integer[] rotateLeft (Integer[]input) {
73
+            Integer[] enter = new Integer[input.length];
74
+            for (Integer i = 0; i < enter.length; i++) {
75
+                enter[i] = input[i + 1];
76
+                }
77
+            return enter;
78
+        }
79
+
80
+        /**
81
+         * Given an array of ints, figure out which is element in the array is largest,
82
+         * and set all the other elements to be that value. Return the changed array.
83
+         * example : maxValue([1, 2, 3]); // Should return [3,3,3]
84
+         *           maxValue([5, 11, 9]); // Should return [11,11,11]
85
+         */
86
+        public Integer[] maxValue (Integer[]input){
87
+            Integer maxValue = input[0];
88
+            for(Integer i = 0; i < input.length; i++){
89
+                if(input[i] > maxValue){
90
+                    maxValue = input[i];
91
+
92
+                }
93
+            }
94
+            Integer[]outPut =new Integer[input.length];
95
+            for(int j=0;j<input.length;j++){
96
+                outPut[j]=maxValue;
97
+            }
98
+            return outPut;
99
+        }
100
+
101
+
102
+        /**
103
+         * Given 2 int arrays, a and b, return a new array length 2 containing their middle elements, if length is odd.
104
+         * If the array length is even the sum of the middle 2 elements in the array.
105
+         * example : middleWay([1, 2, 3], [4,5,6,2]); // Should return [2,11]
106
+         *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
107
+         */
108
+        public Integer[] middleWay (Integer[]input1, Integer[]input2){
109
+            Integer [] newArray = new Integer[2];
110
+            if(input1.length % 2 == 0){
111
+                newArray[0] = input1[input1.length / 2] + input1[input1.length / 2 - 1];
112
+                }
113
+            if(input2.length % 2 == 0){
114
+                newArray[1] = input2[input2.length / 2] + input2[input2.length / 2 -1];}{
115
+                }
116
+                if(input1.length % 2 == 1){
117
+                    newArray[0] = input1[input1.length / 2];
118
+                }
119
+                if(input2.length % 2 == 1){ newArray[1] = input2[input2.length / 2];
120
+            }
121
+            return newArray;
122
+        }
123
+
124
+
125
+
126
+        /**
127
+         * Start with 2 int arrays, a and b, each length 2.
128
+         * Consider the sum of the values in each array.
129
+         * Return the array which has the largest sum. In event of a tie, return a.
130
+         */
131
+        public Integer[] biggerTwo (Integer[]a, Integer[]b){
132
+            Integer suma = a[0] + a[1];
133
+            Integer sumb = b[0] + b[1];
134
+            if(suma > sumb)
135
+            return a;
136
+            {
137
+                return b;
138
+            }
139
+        }
140
+
141
+        /**
142
+         * Given an array of ints of odd length, return a new array length 3 containing the elements from the middle of the array.
143
+         * The array length will be at least 3.
144
+         * example : midThree([1, 2, 3, 4, 5]); // Should return [2, 3, 4]
145
+         *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
146
+         */
147
+        public Integer[] midThree (Integer[]nums){
148
+                    Integer[] newArray = new Integer[3];
149
+            newArray[0] = nums[nums.length / 2 - 1];
150
+            newArray[1] = nums[nums.length / 2];
151
+            newArray[2] = nums[nums.length / 2 + 1];
152
+            return newArray;
153
+        }
76 154
 
77
-    /**
78
-     * Given an array of ints of odd length, return a new array length 3 containing the elements from the middle of the array.
79
-     * The array length will be at least 3.
80
-     * example : midThree([1, 2, 3, 4, 5]); // Should return [2, 3, 4]
81
-     *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82
-     */
83
-    public Integer[] midThree(Integer[] nums){
84
-        return null;
85
-    }
86 155
 }

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

@@ -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