Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passed all tests #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
int count = 0;
String stringArr[] = input.split(" ");
for(String word: stringArr) {
if(word.charAt(word.length() - 1) == 'y' || word.charAt(word.length() - 1) == 'z' ) {
count++;
}
}
return count;
}

/**
Expand All @@ -28,7 +35,8 @@ public Integer countYZ(String input){
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
String result = base.replaceAll(remove, "");
return result;
}

/**
Expand All @@ -40,7 +48,29 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
int countIs = 0;
int countNot = 0;
int index = 0;
while (true) {
index = input.indexOf("is", index);
if (index != -1) {
countIs ++;
index += "is".length();
} else {
break;
}
}
index = 0;
while (true) {
index = input.indexOf("not", index);
if (index != -1) {
countNot ++;
index += "not".length();
} else {
break;
}
}
return countIs == countNot;
}

/**
Expand All @@ -51,7 +81,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
boolean result = true;
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == 'g'){
if (input.charAt(i-1) != 'g' && input.charAt(i+1) != 'g') {
result = false;
}
}
}
return result;
}


Expand All @@ -63,6 +101,13 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
int count = 0;
for (int i = 0; i < input.length()-2; i++){
char x = input.charAt(i);
if(x == input.charAt(i+1) && x == input.charAt(i+2)) {
count++;
}
}
return count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void gIsHappyTest2(){
@Test
public void gIsHappyTest3(){
Boolean actual = stringsAndThings.gIsHappy("xxggyygxx");
Assert.assertTrue(actual);
Assert.assertFalse(actual);
}

}
Binary file added target/classes/io/zipcoder/StringsAndThings.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.