nafis nibir 8 лет назад
Родитель
Сommit
31bf3bba40
2 измененных файлов: 20 добавлений и 20 удалений
  1. 12
    7
      StringArrayUtils.java
  2. 8
    13
      StringArrayUtilsTest.java

+ 12
- 7
StringArrayUtils.java Просмотреть файл

1
- 
2
 
1
 
3
 /**
2
 /**
4
  * Created by leon on 1/29/18.
3
  * Created by leon on 1/29/18.
9
      * @return first element of specified array
8
      * @return first element of specified array
10
      */ // TODO
9
      */ // TODO
11
     public static String getFirstElement(String[] array) {
10
     public static String getFirstElement(String[] array) {
12
-        return null;
11
+        return array[0];
13
     }
12
     }
14
 
13
 
15
     /**
14
     /**
17
      * @return second element in specified array
16
      * @return second element in specified array
18
      */
17
      */
19
     public static String getSecondElement(String[] array) {
18
     public static String getSecondElement(String[] array) {
20
-        return null;
19
+        return array[1];
21
     }
20
     }
22
 
21
 
23
     /**
22
     /**
25
      * @return last element in specified array
24
      * @return last element in specified array
26
      */ // TODO
25
      */ // TODO
27
     public static String getLastElement(String[] array) {
26
     public static String getLastElement(String[] array) {
28
-        return null;
27
+        return array[array.length-1];
29
     }
28
     }
30
 
29
 
31
     /**
30
     /**
33
      * @return second to last element in specified array
32
      * @return second to last element in specified array
34
      */ // TODO
33
      */ // TODO
35
     public static String getSecondToLastElement(String[] array) {
34
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
35
+        return array[array.length-2];
37
     }
36
     }
38
 
37
 
39
     /**
38
     /**
42
      * @return true if the array contains the specified `value`
41
      * @return true if the array contains the specified `value`
43
      */ // TODO
42
      */ // TODO
44
     public static boolean contains(String[] array, String value) {
43
     public static boolean contains(String[] array, String value) {
45
-        return false;
44
+
45
+        for (String test: array){
46
+            if (test.equals(value)){
47
+                return true;
48
+            }        
49
+        }
50
+        return false; 
46
     }
51
     }
47
 
52
 
48
     /**
53
     /**
50
      * @return an array with identical contents in reverse order
55
      * @return an array with identical contents in reverse order
51
      */ // TODO
56
      */ // TODO
52
     public static String[] reverse(String[] array) {
57
     public static String[] reverse(String[] array) {
58
+        
53
         return null;
59
         return null;
54
     }
60
     }
55
 
61
 
103
         return null;
109
         return null;
104
     }
110
     }
105
 
111
 
106
-
107
 }
112
 }

+ 8
- 13
StringArrayUtilsTest.java Просмотреть файл

33
         Assert.assertEquals(expected, actual);
33
         Assert.assertEquals(expected, actual);
34
     }
34
     }
35
 
35
 
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
36
+    
37
+    
38
+    
39
+    
40
+    
41
+    
42
+    
43
+    
49
     @Test
44
     @Test
50
     public void testGetSecondElement1() {
45
     public void testGetSecondElement1() {
51
         String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
46
         String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};