diff --git a/pom.xml b/pom.xml
index d10c35e..6505d27 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,18 @@
com.zipcodewilmington.labs
arrayutils
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 14
+ 14
+
+
+
+
junit
diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
index 4bcce66..eee1f5a 100644
--- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java
+++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
@@ -1,5 +1,7 @@
package com.zipcodewilmington;
+import java.util.*;
+
/**
* Created by leon on 1/29/18.
*/
@@ -9,6 +11,7 @@ public class StringArrayUtils {
* @return first element of specified array
*/ // TODO
public static String getFirstElement(String[] array) {
+
return array[0];
}
@@ -17,6 +20,7 @@ public static String getFirstElement(String[] array) {
* @return second element in specified array
*/
public static String getSecondElement(String[] array) {
+
return array[1];
}
@@ -25,7 +29,8 @@ public static String getSecondElement(String[] array) {
* @return last element in specified array
*/ // TODO
public static String getLastElement(String[] array) {
- return null;
+ int lastIndex = array.length;
+ return array[lastIndex-1];
}
/**
@@ -33,7 +38,8 @@ public static String getLastElement(String[] array) {
* @return second to last element in specified array
*/ // TODO
public static String getSecondToLastElement(String[] array) {
- return null;
+ int s2L = array.length - 2;
+ return array[s2L];
}
/**
@@ -42,6 +48,10 @@ public static String getSecondToLastElement(String[] array) {
* @return true if the array contains the specified `value`
*/ // TODO
public static boolean contains(String[] array, String value) {
+ ArrayList newArray = new ArrayList(Arrays.asList(array));
+ if (newArray.contains(value)){
+ return true;
+ }
return false;
}
@@ -50,7 +60,9 @@ public static boolean contains(String[] array, String value) {
* @return an array with identical contents in reverse order
*/ // TODO
public static String[] reverse(String[] array) {
- return null;
+ ArrayList newArray = new ArrayList(Arrays.asList(array));
+ Collections.reverse(newArray);
+ return newArray.toArray(new String[0]);
}
/**
@@ -58,6 +70,10 @@ public static String[] reverse(String[] array) {
* @return true if the order of the array is the same backwards and forwards
*/ // TODO
public static boolean isPalindromic(String[] array) {
+ String[] palindrome = reverse(array);
+ if (Arrays.equals(array, palindrome)){
+ return true;
+ }
return false;
}
@@ -66,16 +82,41 @@ public static boolean isPalindromic(String[] array) {
* @return true if each letter in the alphabet has been used in the array
*/ // TODO
public static boolean isPangramic(String[] array) {
+
+ String stringArray = Arrays.toString(array).toLowerCase();
+ String alphabet = "abcdefghijklmnopqrstuvwxyz";
+ StringBuilder compareTo = new StringBuilder();
+ for (int i = 0; i < alphabet.length(); i++) {
+ for (int j = 0; j < stringArray.length(); j++) {
+ if (alphabet.charAt(i) == stringArray.charAt(j)){
+ compareTo.append(alphabet.charAt(i));
+ }
+
+ }
+ }
+ System.out.println(compareTo);
+
+
return false;
}
+
+//
+
+
/**
* @param array array of String objects
* @param value value to check array for
* @return number of occurrences the specified `value` has occurred
*/ // TODO
public static int getNumberOfOccurrences(String[] array, String value) {
- return 0;
+ int numOfOccurences = 0;
+ for (String s : array) {
+ if (s == value) {
+ numOfOccurences++;
+ }
+ }
+ return numOfOccurences;
}
/**
@@ -84,7 +125,11 @@ public static int getNumberOfOccurrences(String[] array, String value) {
* @return array with identical contents excluding values of `value`
*/ // TODO
public static String[] removeValue(String[] array, String valueToRemove) {
- return null;
+ ArrayList newArray = new ArrayList(Arrays.asList(array));
+ newArray.remove(valueToRemove);
+ String[] editedArray = newArray.toArray(new String[0]);
+
+ return editedArray;
}
/**
@@ -92,7 +137,15 @@ public static String[] removeValue(String[] array, String valueToRemove) {
* @return array of Strings with consecutive duplicates removes
*/ // TODO
public static String[] removeConsecutiveDuplicates(String[] array) {
- return null;
+ ArrayList editList = new ArrayList<>();
+ String newElement = "";
+ for (String element: array){
+ if (element != newElement){
+ editList.add(element);
+ }
+ newElement = element;
+ }
+ return editList.toArray(new String[0]);
}
/**