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

ht Diana #3

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Conversation

dianasinenchenko
Copy link

No description provided.

@xSAVIKx xSAVIKx self-assigned this Nov 24, 2016
String substring = shortstr.substring(0);
return substring;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite uncommon way to solve this task.
Actually, there is no need for StringBuilder here - you can just use substring method of String.

Also, you can move length check to null-check, so that you'll check string for null and for length<2 and just return s.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means like this ?6cac7fc

String closetag = "</" + tag + ">";
String html = opentag + text + closetag;

return html;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK, but IMO, it's better to solve this task with StringBuilder and the best solution will be using String.format().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with string format e1d526d

return html;

return String.format("%s", "<" + tag + ">"
+ text + "</" + tag + ">");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are almost done.
Now, there is no need to use only one %s in format.
Also, you can combine format with any symbols, so that it should look like: <%s>%s...

@dianasinenchenko dianasinenchenko changed the title ht Diana (1-3) ht Diana (1-4) Nov 26, 2016
if (i > 0 && i >= s.length()) {
i = i - s.length();
}
return String.valueOf(s.charAt(i));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your implementation pass all tests, but you've used lots of unnecessary operations and it'll be quite slow (due to additional usage of Math and StringBuilder.
Try to solve this task from Math point of view - you just need to calculate char index properly and this could be done using % operator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't have any idea. what do you mean about use % operator ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% - is modulus operator in Java.
For example for positive index, result index on which you can get needed char could be calculated in following way:
int index %=s.length().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, interesting. thx


if (lengthA >= 1 && lengthB >= 1) {
return a[0] == b[0] || a[a.length - 1] == b[b.length - 1] || a[0] == b[b.length - 1] || a[a.length - 1] == b[0];
}
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again. It do pass all tests, but it's again to complicated.
Why do you need this if clause ? Also there is no need for lengthA and lengthB vars (or you should reuse them everywhere).
By the task description: you'll 100% have arrays with length>=1.

@dianasinenchenko dianasinenchenko changed the title ht Diana (1-4) ht Diana (1-5) Nov 27, 2016
return false;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you don't need if clause, as result of your expression is boolean - you can just return it.
  2. you should cover one more case - last a is equal to last b.

@dianasinenchenko dianasinenchenko changed the title ht Diana (1-5) ht Diana (1-7) Nov 27, 2016
for (int i = arr.length - 1; i >= 0; --i) {
reverseArr[i] = arr[n];
n++;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create more complex for condition:

for (int i = arr.length - 1, n=0; i >= 0 && n<arr.length; i--, n++) {
  reverseArr[i] = arr[n];
}

But, actually, this task could be solved with only one index variable.

}
int n = 0;
for (int i = arr.length - 1; i >= 0; --i)
if (arr[i] % 2 == 0 || arr[i] == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for you additional condition arr[i]==0 cause even when arr[i] will be 0 - 0%2 ==0 will return true.

@xSAVIKx
Copy link
Member

xSAVIKx commented Nov 30, 2016

@dianasinenchenko Please remove wrong import from Task6, cause due to this import your code could not be compiled.

@xSAVIKx
Copy link
Member

xSAVIKx commented Nov 30, 2016

@dianasinenchenko What about task 9 and task 10 ?

@dianasinenchenko
Copy link
Author

@xSAVIKx i try writing correct pattern for task 9. will be today

@xSAVIKx
Copy link
Member

xSAVIKx commented Dec 1, 2016

@dianasinenchenko What exact problems do you have ? If you need any assistance - it's better to ask questions via Gitter

StringBuilder surl = new StringBuilder();
if (murl.find()){
surl.append(murl.group()).append("\n");
return new String[]{surl.toString()};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid such naming.
Characters are free of charge now and you can easily create names with any length.
Also, follow lowerCamelCase for variables names.
Following names would be better:
url -> regexp
purl -> urlPattern
murl -> urlMatcher
surl -> result.
Also, you need to provide String[3] array and with current implementation you'll supply String[1] array, as surl.toString() will create one String object.


String url =" ( (?<=\\:\\/\\/) [\\w] +.) ? ((?<= \\/\\/) [\\w\\d.-_] +.) ((?<=\\: ) [\\d] ) ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure, that your regexp is not correct.
Schema could contain only [a-zA-Z0-9].
Host could contain [a-zA-Z0-9-_.]
Port could have more than 1 number

@dianasinenchenko dianasinenchenko changed the title ht Diana (1-7) ht Diana Dec 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants