8 kyu
Exclamation marks series #1: Remove an exclamation mark from the end of string
11,968 of 31,994myjinxin2015
Loading description...
Fundamentals
Strings
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
now on dart Translation Dart
This was a very good kata for JavaScript
This comment has been hidden.
Please don't share solutions like that.
python new test framework is required. updated in this fork
Approved
I am getting "IndexError: string index out of range" error
if you write a solution in python, you should consider slice instead of using s[-1]. However, it is just a temprary solution to avoid that error, so let me know if you got a better solution.
Scala translation
Approved
Why do we need to remove only one character at the end, not all of them? This is strange.
The point of this series of katas is to get familiar with basic strings manipulations. So it may be strange, but you should not worry about that, try to do it.
This comment has been hidden.
What if your input is an empty string?
ok got it thx
This comment has been hidden.
Your code should be able to handle empty strings, but it throws
IndexError
instead.Not a kata issue.
I thought the question asked me to remove all trailing exclamation marks, then I was surprised at how incredibly hard it is to do in BF for an 8 kyu kata. Turns out that I mis-understood the kata completely. ;P
got to learn the mistakes I'm doing. Good Kata
very fun!Good job!
C: solutions performing out-of-bounds writes for empty strings pass the tests. A test like
cr_assert_str_eq(remove_mark("!" + 1) - 1, "!");
should be added.all invalidated, thanks for the report
description should be language-agnostic (Removal of function name)
done
Also, description should be language-agnostic
overkill
The note which forbids raising issues on the kata is not necessary.
.
Python testss are very noisy, they print to stdout a lot.
.
COBOL translation (author inactive).
approved
Yo, i'm getting a strange error on this. I'm pulling the last char of the String using the index s[-1] but i got a string index out of range error. I'm assuming that this means it's testing using a null or empty string at some point, which is kind of cheeky. One could assume that you'll always be passed a string with Something in it right?
I know, i know. validate your inputs. But still, after passing all tests and still getting an error, it's a bit frustrating.
-traceback below-
Traceback (most recent call last): File "tests.py", line 17, in test.assert_equals(remove(inp), exp) File "/workspace/default/solution.py", line 2, in remove if (s[-1] == '!'): IndexError: string index out of range
This comment has been hidden.
C translation (author gone)
Approved :)
Please fix the grammar in the description. Instead of "Remove a exclamation...", it should be "Remove an exclamation...".
Done.
I pass all the tests but attempt fails still with all the tests passed.
Traceback (most recent call last): File "tests.py", line 17, in test.assert_equals(remove(inp), exp) File "/workspace/default/solution.py", line 2, in remove if s[-1] == '!': IndexError: string index out of range
Do you pass the sample test or the full test suite? Did you make sure to test for empty strings?
It was written "Congrats you have passed all the tests" No, I have not checked for empty strings, because it's written not to check.
It says you dont need to worry to check if input is a string. It does not say you dont need to check if its empty, i.e "".
you have not yet solved this kata; I passed test an attempt and still count it as unfinish
You need to "submit" not just attempt. Good luck friend!
This comment has been hidden.
What's the input that could cause that error? What do you think?
You're not running the same tests locally (because there's more tests than the ones you see), so you didn't catch this edge case.
Your code failing is not a kata issue, but feel free to reply if you can't figure it out.
If a lvl 8 kata tells me not to worry about input verification and the examples show no empty string, then I'm inclined to call this a kata issue.
It only says the input will be a string, but an empty string is still a valid string :/
I don't think it's an issue TBH. It would be up to the author if he wanted to modify description, or add enother example, but he's gone for a while now. If you feel the need for it, you could raise a suggestion about this.
why does rtrim($s, '!') fail the test?
This comment has been hidden.
In the future, refer to problems in your code as
Question
, not asIssue
. Issue is a problem with a kata (i.e., wrong tests, description, etc.).Your code incorrectly handles some cases. I suggest you to troubleshoot your solution, by printing the input. You may also want to read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
Wait.. the function you're in is called Remove, and you're calling it inside itself. Which isn't necessarily always an issue, but there's only 1 argument to Remove(string s) and you're passing 2 when you call it in the line string result = s.Remove(i, 1)
This comment has been hidden.
This comment has been hidden.
manual notificaiton - see above
Ok, so if its empty then the else statement should happen?
No, it'll throw the error instead.
This comment has been hidden.
Because you're not doing what the kata asks, read the instructions again, it is much more simpler than you think.
Also, Python code without indentation, is very hard to read, please, use markdown formatting when posting code.
This comment has been hidden.
Sorry, but I don't get what
a
is in the first code, maybe you meants
there? You're returning a list in that case and it'll break with some input value. The last code is ok.This comment has been hidden.
What are you using that loop for? That code is not even returning a string. Do you see why it's wrong now?
This comment has been hidden.
Because you're passing a list with a string inside there and here the input is a string. And no, it returns a list with a string inside, not a string, do you see the
[]
there?Okay now I understand why that happens xD
Thanks!
Passed all the test but got an error. Whats the deal?
The following code doesn't work properly: $s[-1]. I can't access string character by using negative index. I have checked it on my PHPStorm, on old PHP versions (5.4, 7.0) and it works correctly.
Not a kata issue, it's like that in PHP 7.0
Thank You!
I have actully changed PHP version in my IDE settings, but I haven't changed my php config file. Nevertheless, it would be nice if newer PHP versions were supported.
This comment has been hidden.
It doesn't, because your solution raises an error.
It *clearly says right here I passed all test. Why bother answering if your not going to read what was posted and then mark it as resolved? I know it's not an acceptable answer hence the exit code 1. What I am trying to understand is *why it through that code and how to resolve it. If your not going to do that then why bother replying with an answer that is of no use or any help.
```Time: 656ms Passed: 6 Failed: 0 Exit Code: 1 Test Results: Basic Tests Test Passed Test Passed Test Passed Test Passed Test Passed Test Passed
It passed all tests until your code raised that error. There are more tests, 107 in total for Python. Reading the error message and printing the input will help you.
This comment has been hidden.
empty string? ;-)
It may be that I guess, gonna try that out, thanks for the tip :)!!
Man I am not sure it is 8 kyu. It's not that easy for beginners. Great idea! Had fun with it!
Happy coding
^_^
Agree, it was suprisingly rich, for such an easy task. :-D
It was so easy though ????
I love your katas, I need to leave my routines and really think, not just apply mechanical schemes, even in the cases of simple katas.
Thanks. Happy coding
^_^
Thanks. Happy coding
^_^
This comment has been hidden.
Hi, I made a C# translation for this Kata, please review and approve.
Solved the samples with no problems, but when I submit I get STDERR error saying list index is out of range. Bug of exercice or me?
Python? I guess that you are using -1 in your code, and then your code passed in an empty string, and then.. ;-)
Thanks man! Realy helpfull ;)
Edit: nevermind, got it :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You shouldn't post answers in the Discourse section
In PHP there seems to be an error caused by PhpUnit, it says it can't assert two strings equality.
This comment has been hidden.
@Anvar Turobov, your solution is not passing all the tests. Add
test.assert_equals(remove(""), "")
in "Example Tests" and see what happens.thanks @kazk, it makes sense now, I was not checking the length of the string, I've fixed it.
'Looks like you've solved it'
This comment has been hidden.
Your code will failed when s is an empty string ;-)
Aha thanks, passed it. I was frustrated at first because I didn't know what is going on and why am I getting an error but now I m fine :)
got everything to pass except a long random test. i can print s that is passed in and it doesn't match the output on the expected result displayed any reason why the string in and string expected would be different?
**to clarify-I don't mean they are different due to the last !, the letters/chars start to differ after several lines in
Which language are you using?
python
Python version is a translation from @suic I've checked the test code and I haven't find out any error(Please forgive me for my poor Python skills) I modified something of random tests:
Thanks for the quick response. works perfect now, passes all. I'm not the best with string/char manipulation. I spent a lot of time on it and when the large random test didn't match I wanted to check.
;-)
In python,
I get a failure message stating:
'Hi' should equal 'Hi!!'
That seems to go against both the instructions as well as the sample tests shown. "Hi" should return "Hi" unless I'm totally missing something obvious.
Sorry for the delay, because I haven't saw your comment(CW did not give me a notice) 'Hi' should equal 'Hi!!' means that your result is 'Hi' but reference result is 'Hi!!', because original string is 'Hi!!!' ;-) You should not remove all the exclamation marks from the end of string. You need remove only one exclamation mark from the end of string.
Haskell translation kumited. Please review and approve. Thanks, suic
All approved, thanks ;-)
Thanks :)
PHP Translation Kumited - please accept :D And it's got random tests ;)
Approved, thanks ;-)
This comment has been hidden.
Thanks ;-) Could you add some random tests?
Yeah i will.
This comment has been hidden.
This comment has been hidden.
I'm the author of Javascript, but I don't know this language ;-) Please waiting for the translator take a look ;-)
I add
print (i)
in front of yourif
statement I can see the first i is 'H'. It's a string, I think you want get the index of x, but it's not the index.And del can not using for string And this kata only need to remove one "!" from the end of string, instead of all the "!"
Ruby translation available here. Crystal translation available here
Please review and accept if everything is ok.
CoffeeScript translation Kumited! Please Accept :D
Approved, thanks ;-)
TY! :D
hmmm. all test cases pass but when i submit, i get an error Time: 68ms Passed: 6 Failed: 0 Test Results: Basic Tests (6 Passed, 0 Failed) STDERR: Traceback: in in remove IndexError: string index out of range
perhaps your code sometimes generate some invalid index, such as -1, null..
Could your exercise possibly at least show what input causes user's code to crash?
I am not really sure how difficult would it be but for I beginner as myself it would be really appreciated :) Frankly, my code passes the basic tests but I am getting same error as cbira353.
You can paste your code here, let me see ;-) (please Mark it as having spoiler content)
This comment has been hidden.
your code failed at
s=""
;-)Aha, I see :-) Thank you very much again! This really helps!
This comment has been hidden.
empty string can not get -1, you can use
return "" if s ==""
in front of other code.Add the empty string to Python tests--some solutions will fail.
Good point :) Done!
Regards,
suic
If you would like to mess up a bit with people who used regex a test like this is quite interesting: 'Hello!\n'; some people will surely remove exclamation mark :) PS: Sorry for being always late to the party!
@suic, Don't add more corner case, this is a beginner kata, no needed more complex situation ;-)
Do you think it's better for a beginner to think their wrong solution is right? The right solution with regexps isn't more complicated but just different.
for this kata, the question is:
can you remove a exclamation mark from the end of string?
since suic add empty string as input, question became to:is this a empty string? + can you remove a exclamation mark from the end of string?
if we add 'Hello!\n' to the tests, question became to:is this a empty string? + where is the end of string? + can you remove a exclamation mark from the end of string?
if we add other data type(number, array, etc..) to the tests, question became to:is this a string? + is this a empty string? + where is the end of string? + can you remove a exclamation mark from the end of string?
Their diffculty are diffrent ;-)An empty string is a case or an arbitrary string not ending with '!'. If an empty string is not a valid input then I think it should be explicitly stated so.
It's not about removing the exclamation mark from
Hello!\n
, it's about keeping it. The answer definitely isHello!\n
, the point is that some Python regexp solutions do remove the exclamation mark in this case.I hope I can keep the status quo... My original title is "...from the end of sentence", not "... end of string". You said that "Hi! Hi!" is two sentence, OK, I modify kata's title to "...from the end of string" Now, you said that "" is a valid string, OK, I can add "please note input can be a empty string" @cbira353(7 kyu) and @MatthewStevens(7 kyu) said:"hmmm. all test cases pass but when i submit, i get an error", but they don't know why. OK, I can told them: "Your code failed on s=''"(see comment above)... Oh, no. I do not want to use more strange test to increase the user's confusion. I hope my 8kyu kata is simple enough. Please let me keep the status quo ;-))))))
Whatever. I'm just imagining some SQL kata without any tests with quotes inside so that beginners don't get confused when their solutions fail. And the they make sites...
may want to re-read this https://bkaestner.github.io/codewars-rules/ and https://www.codewars.com/topics/kata-best-practices pages when writing kata tests.
wait wait I'm getting quoted now? :P
OHHH, I see my quote has been taken out of context, thanks for that :)
I see you've created this kata series somewhat in spite of the comment I made.
Yes :) It's fixed now. The quote referes to the source.
Regards,
suic
oh, that's fine it's myjinxin2015's reaction to that comment that concerns me.
Python translation kumited. Please review and approve.
Regards,
suic
;-)
Thanks :)
Btw, this:
is amazing. Good way to prevent a process with Duplication Inquisition :) (Python translation increases the probability of such process :))
Regards,
suic
P. S.: I know you that you don't like duplicate kata ;)
Maybe add some example test case. I found really useful for beginner.
Just forgot to copy&paste ;-) Added.
That was my guess.
That's awesome! I like the way it all began with a comment. I hope no one's feelings are hurt.
Hi! Hi!
is two sentences.Please call
s
as a sentence and call each part as a word...or I modify the title to
Remove a exclamation mark from the end of string
?This would probably be better than redefining existing terms.
OK. modified ;-)