From 7fb07a0bdff8f1f2b768b2828892e869c44062e5 Mon Sep 17 00:00:00 2001 From: sitarameez Date: Tue, 29 Jun 2021 19:24:27 -0400 Subject: [PATCH 1/4] finished few tests some with skeleton --- .../zipcodewilmington/StringArrayUtils.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 4bcce66..86c552f 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -17,6 +17,7 @@ public static String getFirstElement(String[] array) { * @return second element in specified array */ public static String getSecondElement(String[] array) { + return array[1]; } @@ -25,7 +26,11 @@ public static String getSecondElement(String[] array) { * @return last element in specified array */ // TODO public static String getLastElement(String[] array) { - return null; + String result=""; + + result = array[array.length-1]; + + return result; } /** @@ -33,7 +38,9 @@ public static String getLastElement(String[] array) { * @return second to last element in specified array */ // TODO public static String getSecondToLastElement(String[] array) { - return null; + String result=""; + result=array[array.length-2]; + return result; } /** @@ -42,15 +49,24 @@ 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; + Boolean result=false; + for (String word : array) { + if (word == value) { + result = true; + } + } + return result; } - /** * @param array of String objects * @return an array with identical contents in reverse order */ // TODO public static String[] reverse(String[] array) { - return null; + String result[]={}; + for(int i=array.length-1;i>=0;i--){ + result+= array[i]; + } + return result; } /** @@ -58,7 +74,17 @@ 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; + Boolean result=false; +// for(int i=0;i=0;i--){ +// +// } +// if(==){ +// +// } + return result; } /** From 2e51d30d9df9420e36be20f3dadfa9faddd02451 Mon Sep 17 00:00:00 2001 From: sitarameez Date: Wed, 30 Jun 2021 19:48:05 -0400 Subject: [PATCH 2/4] still figuring out the rest --- .../zipcodewilmington/StringArrayUtils.java | 79 +++++++++++++++---- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 86c552f..0ab4d63 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,5 +1,8 @@ package com.zipcodewilmington; +import java.util.ArrayList; +import java.util.Arrays; + /** * Created by leon on 1/29/18. */ @@ -62,9 +65,11 @@ public static boolean contains(String[] array, String value) { * @return an array with identical contents in reverse order */ // TODO public static String[] reverse(String[] array) { - String result[]={}; + String[] result= new String[array.length]; + int j = 0; for(int i=array.length-1;i>=0;i--){ - result+= array[i]; + result[j]= array[i]; + j++; } return result; } @@ -74,17 +79,13 @@ 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) { - Boolean result=false; -// for(int i=0;i=0;i--){ -// -// } -// if(==){ -// -// } - return result; + Boolean result= true; + for(int i=0;i tempArray = new ArrayList(); + for(int i = 0;i arrayList = new ArrayList(); + ArrayList tempArrayList = new ArrayList(); + for(int i = 0;i< array.length;i++) { + tempArrayList.add(array[i]); + //arrayList.add(array[i]); + if(i>0) { + if(array[i].equals(array[i - 1])) + { + tempArrayList.remove(tempArrayList.size()-1); + } + } + } + String[] result= new String[tempArrayList.size()]; + return result; } /** From 8bf7b832f4a32980f13a0d5ea7d8f3ff48e66432 Mon Sep 17 00:00:00 2001 From: sitarameez Date: Fri, 2 Jul 2021 00:41:08 -0400 Subject: [PATCH 3/4] one more to go --- .../zipcodewilmington/StringArrayUtils.java | 90 +++++++++++-------- .../GetConsecutiveDuplicatesTest.java | 2 +- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 0ab4d63..cf9c9a6 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 com.sun.org.apache.xpath.internal.operations.Bool; + import java.util.ArrayList; import java.util.Arrays; @@ -29,9 +31,9 @@ public static String getSecondElement(String[] array) { * @return last element in specified array */ // TODO public static String getLastElement(String[] array) { - String result=""; + String result = ""; - result = array[array.length-1]; + result = array[array.length - 1]; return result; } @@ -41,8 +43,8 @@ public static String getLastElement(String[] array) { * @return second to last element in specified array */ // TODO public static String getSecondToLastElement(String[] array) { - String result=""; - result=array[array.length-2]; + String result = ""; + result = array[array.length - 2]; return result; } @@ -52,7 +54,7 @@ public static String getSecondToLastElement(String[] array) { * @return true if the array contains the specified `value` */ // TODO public static boolean contains(String[] array, String value) { - Boolean result=false; + Boolean result = false; for (String word : array) { if (word == value) { result = true; @@ -60,15 +62,16 @@ public static boolean contains(String[] array, String value) { } return result; } + /** * @param array of String objects * @return an array with identical contents in reverse order */ // TODO public static String[] reverse(String[] array) { - String[] result= new String[array.length]; + String[] result = new String[array.length]; int j = 0; - for(int i=array.length-1;i>=0;i--){ - result[j]= array[i]; + for (int i = array.length - 1; i >= 0; i--) { + result[j] = array[i]; j++; } return result; @@ -79,13 +82,13 @@ 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) { - Boolean result= true; - for(int i=0;i tempArray = new ArrayList(); - for(int i = 0;i tempArray = new ArrayList(); + for (int i = 0; i < array.length; i++) { + if (!array[i].equals(valueToRemove)) { + tempArray.add(array[i]); } } @@ -150,29 +150,47 @@ public static String[] removeValue(String[] array, String valueToRemove) { * @return array of Strings with consecutive duplicates removes */ // TODO public static String[] removeConsecutiveDuplicates(String[] array) { - //ArrayList arrayList = new ArrayList(); + ArrayList tempArrayList = new ArrayList(); - for(int i = 0;i< array.length;i++) { + for (int i = 0; i < array.length; i++) { tempArrayList.add(array[i]); - //arrayList.add(array[i]); - if(i>0) { - if(array[i].equals(array[i - 1])) - { - tempArrayList.remove(tempArrayList.size()-1); + if (i > 0) { + if (array[i].equals(array[i - 1])) { + tempArrayList.remove(tempArrayList.size() - 1); } } } - String[] result= new String[tempArrayList.size()]; + String[] result = new String[tempArrayList.size()]; + result = tempArrayList.toArray(result); return result; } + /** * @param array array of chars * @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; - } + ArrayList tempArrayList = new ArrayList(); +//{"a", "a", "a", "b", "c", "c", "a", "a", "d"}; + int j = 0; + tempArrayList.add(array[0]); + for(int i = 1; i < array.length; i++){ + if(tempArrayList.get(j).contains(array[i])) + { + tempArrayList.set(j, (tempArrayList.get(j) + array[i])); + } + else + { + j++; + tempArrayList.add(array[i]); + } + } + + String[] result = new String[tempArrayList.size()]; + result = tempArrayList.toArray(result); -} + return result; + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/GetConsecutiveDuplicatesTest.java b/src/test/java/com/zipcodewilmington/GetConsecutiveDuplicatesTest.java index 2e188d6..3827f13 100644 --- a/src/test/java/com/zipcodewilmington/GetConsecutiveDuplicatesTest.java +++ b/src/test/java/com/zipcodewilmington/GetConsecutiveDuplicatesTest.java @@ -34,4 +34,4 @@ public void testRemoveConsecutiveDuplicates3() { Assert.assertEquals(actual, expected); } -} +} \ No newline at end of file From 688984ed90eff4f1565acce764882284ad31eb46 Mon Sep 17 00:00:00 2001 From: sitarameez Date: Fri, 2 Jul 2021 13:15:45 -0400 Subject: [PATCH 4/4] finished but still want to try something --- pom.xml | 12 +++++++++ .../zipcodewilmington/StringArrayUtils.java | 25 ++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index d10c35e..4d4515a 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 + + 8 + 8 + + + + junit diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index cf9c9a6..4b34404 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -96,20 +96,17 @@ 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) { - Boolean result = true; -// -// for (int i = 0; i < array.length; i++) { -// if ('A' <= array.charAt(i) && array.charAt(i) <= 'Z') { -// alphabetIndex = array.charAt(i) - 'A'; -// alphabetMarker[alphabetIndex] = true; -// } -// } -// for (boolean index : alphabetMarker) { -// if (!index) { -// return false; -// } -// } - return result; + String check=String.join("",array).toLowerCase(); + String[] letters={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; + for(int i=0;i