Seth il y a 6 ans
Parent
révision
5c2dbf38ac
1 fichiers modifiés avec 23 ajouts et 5 suppressions
  1. 23
    5
      src/main/java/com/zipcodewilmington/StringArrayUtils.java

+ 23
- 5
src/main/java/com/zipcodewilmington/StringArrayUtils.java Voir le fichier

1
 package com.zipcodewilmington;
1
 package com.zipcodewilmington;
2
 
2
 
3
+
3
 /**
4
 /**
4
  * Created by leon on 1/29/18.
5
  * Created by leon on 1/29/18.
5
  */
6
  */
9
      * @return first element of specified array
10
      * @return first element of specified array
10
      */ // TODO
11
      */ // TODO
11
     public static String getFirstElement(String[] array) {
12
     public static String getFirstElement(String[] array) {
12
-        return null;
13
+
14
+        return array[0];
13
     }
15
     }
14
 
16
 
15
     /**
17
     /**
17
      * @return second element in specified array
19
      * @return second element in specified array
18
      */
20
      */
19
     public static String getSecondElement(String[] array) {
21
     public static String getSecondElement(String[] array) {
20
-        return null;
22
+
23
+        return array[1];
21
     }
24
     }
22
 
25
 
23
     /**
26
     /**
25
      * @return last element in specified array
28
      * @return last element in specified array
26
      */ // TODO
29
      */ // TODO
27
     public static String getLastElement(String[] array) {
30
     public static String getLastElement(String[] array) {
28
-        return null;
31
+
32
+        return array[array.length - 1];
29
     }
33
     }
30
 
34
 
31
     /**
35
     /**
33
      * @return second to last element in specified array
37
      * @return second to last element in specified array
34
      */ // TODO
38
      */ // TODO
35
     public static String getSecondToLastElement(String[] array) {
39
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
40
+
41
+        return array[array.length - 2];
37
     }
42
     }
38
 
43
 
39
     /**
44
     /**
42
      * @return true if the array contains the specified `value`
47
      * @return true if the array contains the specified `value`
43
      */ // TODO
48
      */ // TODO
44
     public static boolean contains(String[] array, String value) {
49
     public static boolean contains(String[] array, String value) {
50
+        for(String counter : array) {
51
+            if(counter.equals(value)) {
52
+                return true;
53
+            }
54
+        }
55
+
45
         return false;
56
         return false;
46
     }
57
     }
47
 
58
 
50
      * @return an array with identical contents in reverse order
61
      * @return an array with identical contents in reverse order
51
      */ // TODO
62
      */ // TODO
52
     public static String[] reverse(String[] array) {
63
     public static String[] reverse(String[] array) {
53
-        return null;
64
+        String[] reverseArray = new String[array.length];
65
+        for(int i = 0; i < array.length - 1; i++){
66
+            reverseArray[] += array[i];
67
+
68
+            }
69
+
70
+
71
+            return reverseArray;
54
     }
72
     }
55
 
73
 
56
     /**
74
     /**