From 6a03a0c099be84ba38f661a54e38c4b521b9ba3a Mon Sep 17 00:00:00 2001 From: Raymond Date: Thu, 1 Jul 2021 16:32:49 -0400 Subject: [PATCH 1/2] Help me Leon --- .../zipcodewilmington/StringArrayUtils.java | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 4bcce66..bb6f2c5 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,5 +1,10 @@ package com.zipcodewilmington; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + /** * Created by leon on 1/29/18. */ @@ -9,6 +14,7 @@ public class StringArrayUtils { * @return first element of specified array */ // TODO public static String getFirstElement(String[] array) { + return array[0]; } @@ -17,6 +23,7 @@ public static String getFirstElement(String[] array) { * @return second element in specified array */ public static String getSecondElement(String[] array) { + return array[1]; } @@ -25,7 +32,8 @@ public static String getSecondElement(String[] array) { * @return last element in specified array */ // TODO public static String getLastElement(String[] array) { - return null; + String lastElement = array[array.length - 1]; + return lastElement; } /** @@ -33,7 +41,8 @@ public static String getLastElement(String[] array) { * @return second to last element in specified array */ // TODO public static String getSecondToLastElement(String[] array) { - return null; + String secondToLastElement = array[array.length - 2]; + return secondToLastElement; } /** @@ -41,8 +50,11 @@ public static String getSecondToLastElement(String[] array) { * @param value value to check array for * @return true if the array contains the specified `value` */ // TODO - public static boolean contains(String[] array, String value) { - return false; + public static boolean contains(String[] array, String value) { + for (int i = 0; i < value.length(); i++){ + if(array[i] == value); + } + return true; } /** @@ -50,17 +62,38 @@ 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; + List list = Arrays.asList(array); + Collections.reverse(list); + String[] reverseList = list.toArray(array); + return reverseList; } /** * @param array array of String objects * @return true if the order of the array is the same backwards and forwards */ // TODO + + //identify midpoint of an array + //identify last index + //for loop + public static boolean isPalindromic(String[] array) { - return false; + List list = Arrays.asList(array); + // System.out.println(list); + Collections.reverse(list); + // System.out.println(list); + String[] reverseArray = list.toArray(new String[array.length]); + for (int i = 0; i < reverseArray.length; i++) { + String thisString = reverseArray[i]; + String thisOtherString = array[i]; + if (!thisString.equals(thisOtherString)) { + return false; + } + } + return true; } + /** * @param array array of String objects * @return true if each letter in the alphabet has been used in the array From 93c744a48d4eb6917a25fe448cd9c5a2b95a07b6 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sat, 3 Jul 2021 12:11:06 -0400 Subject: [PATCH 2/2] Raymond Fitzgerald --- .../zipcodewilmington/StringArrayUtils.java | 87 ++++++++++++++++--- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index bb6f2c5..6a57b1b 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,9 +1,8 @@ package com.zipcodewilmington; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.lang.reflect.Array; +import java.util.*; /** * Created by leon on 1/29/18. @@ -78,10 +77,8 @@ public static String[] reverse(String[] array) { //for loop public static boolean isPalindromic(String[] array) { - List list = Arrays.asList(array); - // System.out.println(list); + List list = Arrays.asList(array.clone()); Collections.reverse(list); - // System.out.println(list); String[] reverseArray = list.toArray(new String[array.length]); for (int i = 0; i < reverseArray.length; i++) { String thisString = reverseArray[i]; @@ -99,7 +96,26 @@ 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; + /* convert array of string to one string + nested for loop with original string on outside and alphabet on inside + every time they match copy that to a new array + remove duplicates + if that array matches array of the alphabet + return true + */ + ArrayList stringOfArrays = new ArrayList(Arrays.asList(array)); + String newString = stringOfArrays.toString().toLowerCase(); + String aBCS = "abcdefghijklmnopqrstuvwxyz"; + for (int i = 0; i < aBCS.length(); i++){ + if (newString.indexOf(aBCS.charAt(i)) == -1 ){ + return false; + } + } + + + + + return true; } /** @@ -108,7 +124,12 @@ 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; + int counter = 0; + for (int i = 0; i < array.length; i++) { + if (value.equals(array[i])) + counter++; + } + return counter; } /** @@ -117,7 +138,10 @@ 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 list = new ArrayList(Arrays.asList(array)); + list.remove(valueToRemove); + array = list.toArray(new String[0]); + return array; } /** @@ -125,16 +149,51 @@ 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 newArrayList = new ArrayList(); + newArrayList.add(array[0]); + for (int i = 1; i < array.length; i++){ + if(array[i] != array[i - 1]){ + newArrayList.add(array[i]); + } + + } + + + return newArrayList.toArray(new String[newArrayList.size()]); + } + + /** * @param array array of chars - * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings + * @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; +// iterate through array with for loop counter +// identify if character in string is the same as the next character +// if they are same, concatenate +//add concatenation to new string array + + /* StringBuilder stringBuilder = new StringBuilder(arrayToString.charAt(i)).append(arrayToString.charAt(i+1)); + if(stringBuilder.lastIndexOf()) + String newString = stringBuilder.toString(); + String[] stringWithSpaces = newString.split(" "); + array = stringWithSpaces;*/ + ArrayList list = new ArrayList(); + list.add(array[0]); + int counter = 0; + for (int i = 1; i < array.length; i++) { + if(list.get(counter).contains(array[i])){ + list.set(counter, list.get(counter) + array[i]); + + }else{ + counter++; + list.add(array[i]); + } + } + return list.toArray(new String[0]); } - - }