From e2dfa424cb4c096f438a373e2c5ce6932572de48 Mon Sep 17 00:00:00 2001
From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com>
Date: Sun, 4 Jul 2021 11:19:19 -0400
Subject: [PATCH 1/3] reverse tests passed
---
pom.xml | 12 ++++++++++++
.../java/com/zipcodewilmington/StringArrayUtils.java | 8 +++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d10c35e..991cf63 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,18 @@
com.zipcodewilmington.labsarrayutils1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+ junit
diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
index 4bcce66..9328870 100644
--- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java
+++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
@@ -50,7 +50,13 @@ 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;
+ String [] revArray = new String[array.length];
+ int newArray = 0;
+ for (int i = array.length - 1; i >= 0; i--) {
+ revArray[newArray] = array[i];
+ newArray++;
+ }
+ return revArray;
}
/**
From 6311855d1245842d312f76116e14dbf4ed336090 Mon Sep 17 00:00:00 2001
From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com>
Date: Wed, 7 Jul 2021 16:05:29 -0400
Subject: [PATCH 2/3] Cannot get the dupes to pass yet
---
.../zipcodewilmington/StringArrayUtils.java | 52 +++++++++++++++----
1 file changed, 43 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
index 9328870..52447e0 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.
*/
@@ -17,7 +19,7 @@ public static String getFirstElement(String[] array) {
* @return second element in specified array
*/
public static String getSecondElement(String[] array) {
- return array[1];
+ return array[1];
}
/**
@@ -25,7 +27,8 @@ public static String getSecondElement(String[] array) {
* @return last element in specified array
*/ // TODO
public static String getLastElement(String[] array) {
- return null;
+
+ return array[array.length-1];
}
/**
@@ -33,7 +36,7 @@ public static String getLastElement(String[] array) {
* @return second to last element in specified array
*/ // TODO
public static String getSecondToLastElement(String[] array) {
- return null;
+ return array[array.length-2];
}
/**
@@ -42,7 +45,8 @@ public static String getSecondToLastElement(String[] array) {
* @return true if the array contains the specified `value`
*/ // TODO
public static boolean contains(String[] array, String value) {
- return false;
+ List arrayList = new ArrayList(Arrays.asList(array));
+ return arrayList.contains(value);
}
/**
@@ -64,7 +68,8 @@ 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) {
- return false;
+ String[] revArray = reverse(array);
+ return Arrays.equals(revArray, array);
}
/**
@@ -72,7 +77,16 @@ 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) {
- return false;
+ String pangramic = Arrays.toString(array);
+ pangramic = pangramic.toLowerCase(Locale.ROOT);
+ if (pangramic.length() < 26) {
+ return false;
+ } else
+ for (char i = 'a'; i <= 'z'; i++) {
+ if (pangramic.indexOf(i) == -1)
+ return false;
+ }
+ return true;
}
/**
@@ -81,7 +95,9 @@ public static boolean isPangramic(String[] array) {
* @return number of occurrences the specified `value` has occurred
*/ // TODO
public static int getNumberOfOccurrences(String[] array, String value) {
- return 0;
+ List arrayList = new ArrayList(Arrays.asList(array));
+ return Collections.frequency(arrayList,value); //collections holds different methods I can use
+
}
/**
@@ -90,7 +106,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;
+ List arrayList = new ArrayList(Arrays.asList(array));
+ while (arrayList.contains(valueToRemove)) {
+ arrayList.remove(valueToRemove);
+ }
+ return arrayList.toArray(new String [0]);
}
/**
@@ -98,7 +118,21 @@ 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;
+// List arrayList = new ArrayList(Arrays.asList(array));
+//
+// arrayList.add(array.(0));
+
+
+
+
+// String consecutive = Arrays.toString(array);
+// if (consecutive.length() <= 1)
+// return array;
+// if (consecutive.charAt(0) == consecutive.charAt(1))
+// return removeConsecutiveDuplicates(consecutive.substring(1));
+// else
+// return con
+ return null;
}
/**
From 4fe096896c4afa7fa3a4386391009cf32072bb00 Mon Sep 17 00:00:00 2001
From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com>
Date: Wed, 7 Jul 2021 22:42:16 -0400
Subject: [PATCH 3/3] Passed the duplicate tests
---
.../zipcodewilmington/StringArrayUtils.java | 35 ++++++++++++-------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
index 52447e0..e6dbbcc 100644
--- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java
+++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java
@@ -118,21 +118,18 @@ public static String[] removeValue(String[] array, String valueToRemove) {
* @return array of Strings with consecutive duplicates removes
*/ // TODO
public static String[] removeConsecutiveDuplicates(String[] array) {
-// List arrayList = new ArrayList(Arrays.asList(array));
-//
-// arrayList.add(array.(0));
+ List arrayList = new ArrayList();
+ String previousElement = "";
+ for (String element : array) {
+ if (element != previousElement) { //if the current element is not equal to the previous then add the element, this will pass over the elemets that are the same
+ arrayList.add(element);
+ }
+ previousElement = element;
+ }
-
-// String consecutive = Arrays.toString(array);
-// if (consecutive.length() <= 1)
-// return array;
-// if (consecutive.charAt(0) == consecutive.charAt(1))
-// return removeConsecutiveDuplicates(consecutive.substring(1));
-// else
-// return con
- return null;
+ return arrayList.toArray(new String[0]);
}
/**
@@ -140,7 +137,19 @@ public static String[] removeConsecutiveDuplicates(String[] array) {
* @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
*/ // TODO
public static String[] packConsecutiveDuplicates(String[] array) {
- return null;
+ int lastIndex = 0;
+ List arrayList = new ArrayList ();
+ arrayList.add(array[0]); //start at index 0
+ for (int i = 1; i < array.length; i++) { // this will start looping at the 1st index that does not have the same character
+ if (arrayList.get(lastIndex).contains(array[i])) { // this is saying if the last index has the current character
+ arrayList.set(lastIndex, (arrayList.get(lastIndex) + array[i])); // will add the duplicate letter to the previous letter
+ }
+ else { // if they are not the same, nothing with be packed together because we are missing duplicates
+ lastIndex++; // go to the next index and have that non duplicate letter start here
+ arrayList.add(array[i]);
+ }
+ }
+ return arrayList.toArray(new String[0]); // return string array
}