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

Filled in all methods to allow to pass all tests #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
54 changes: 49 additions & 5 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


/**
* @author tariq
* @author PaulQ
*/
public class StringsAndThings {

Expand All @@ -15,7 +15,22 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
Integer yaz = 0;
String[] words = input.toLowerCase().split(" ");
for(int i = 0; i < words.length; i++){
int len = words[i].length();
if (Character.isLetter(words[i].charAt(len-1))){
if(words[i].charAt(len - 1) == 'y' || words[i].charAt(len - 1) == 'z'){
yaz++;
}
}
else{
if(words[i].charAt(len - 2) == 'y' || words[i].charAt(len - 2) == 'z'){
yaz++;
}
}
}
return yaz;
}

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

/**
Expand All @@ -40,7 +55,19 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
int iss = 0;
int nots = 0;
int indy = 0;
while((indy = input.indexOf("is",indy)) != -1){
indy+=2;
iss++;
}
indy = 0;
while((indy = input.indexOf("not",indy)) != -1){
indy+=3;
nots++;
}
return iss == nots;
}

/**
Expand All @@ -51,6 +78,17 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
int showedUpToFor = 0;
for(int i = 0; i < input.length(); i++){
char cha = input.charAt(i);
showedUpToFor = 1;
if(cha == 'g') {
if(i + 1 == input.length() || input.charAt(i+1) != 'g'){
return false;
}
return true;
}
}
return null;
}

Expand All @@ -63,6 +101,12 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
Integer trips = 0;
for(int i = 2; i < input.length(); i++){
if(input.charAt(i-1) == input.charAt(i) && input.charAt(i-2) == input.charAt(i)){
trips++;
}
}
return trips;
}
}