8 kyu
Remove String Spaces
113,233 of 273,177PG1
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.
ahahaha very nice kata
This comment has been hidden.
The description is shared among all the languages and "create a query" only applies to SQL.
This comment is in the inital code for SQL:
Простое задание. Если помните методы строк.
This comment has been hidden.
That's not a kata's suggestion, kata's suggestions would be adding some example or test or any other change you think would improve the kata itself, not how to solve it.
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in Discourse.
i tried using the join method and it didn't work. so i just made a big list of letters and numbers as a string to solve it. but i know it's inefficient. what was I doing wrong with the join method that it didn't work. ended up taking 6 lines of code. with the join if i'm not mistaking it should have taken only 2 or 3 right?
This comment has been hidden.
Thank you :)
I am new to codewars and was curious if there is a way to compare solutions based on efficiency (time/space)?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
enjoyed it :)
good question enjoyed it
This question gives me a chance to review the JOIN method!!!
Why can't I use the erase function (in c++)?
This comment has been hidden.
Please don't post solutions in the discourse. See https://docs.codewars.com/training/troubleshooting#post-discourse.
Not a kata suggestion.
I'm sorry... My first day using this site.. How do I delete this line of code? I can't find the edit button...
You can't edit/delete your post after it has been replied to. Don't worry, it's flagged as a spoiler and only people who have completed the kata can see it. In the future, please use the solutions page to discuss solutions.
takoy easy
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Good afternoon,
Im no expert, but const is not changeable once it is declared, so if it is declared in the scope of the whole function, it will be set once and then not change for the duration of the function.
If the const is declared inside the while loop, for each loop the const will be declared as a new variable, and when it cycles to the next loop it is recreated.
Does this work if you change the const above the while loop to 'let'?
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in the kata's Discourse without spoiler flag.
Ok I'm sorry I didn't know about this rule.
How does this pass their QA? there's no examples and no elaborate explanation on the problem. This is specially important for beginners, given how this is an 8 kyu challenge.
the author mentions: "Simple, remove the spaces from the string, then return the resultant string."
but again: you are explaning this to beginners... we need all the help we can get!!
What more do you need? An example? It's pretty self-explanatory imo.
yes, exactly. examples can greatly help beginners understand the problem at hand. Plus to be PC (politically correct), you should not mention 'simple' in the beginning. We already know 8 kyu is simple, but for those who don't know how to solve this, you're just making them feel worse with that terminology.
Is it better now?
Yeah I think that's much better, thanks Chrono :)
I'm sure all of us beginners will appreciate this.
Examples should not help you understand a problem. Specifications should do that.
"Remove spaces" really should not need examples, unless you are hell-bent on reverse engineering the examples to avoid reading the specifications. I see a lot of that ( people insisting on examples ), and I think it's an awful habit to have.
Conversely, a problem specified by examples only very quickly becomes "just read my mind."
If you read the specifications, can't figure out the task, and then resort to reverse engineering the examples to figure out what an author apparently, probably, meant to be the task, it's entirely possible the specs were written badly, but it's also entirely possible you are refusing to read the specs.
Do not refuse to read the specs.
( If the description is written badly, raise an
Issue
. But really, how bad can "remove spaces" be? Which of those words do you need defined? )( This advice worth what you paid for it. Other opinions may be available - but they might be wrong. )
This comment has been hidden.
This comment has been hidden.
I don't know why this is 8 kyu and not 7.
i don't why but it could not pass for me i try on codepen it was okay, but i couldn't pass the assortion
in javascript
Your solution has a bug and I somewhat doubt it worked for you on codepen. Maybe you retyped it incorrectly into Codewars editor?
Anyway, a bug in your solution is not a kata issue.
This comment has been hidden.
Strings are immutable in javascript.
I see,thank you for the answer!
This comment has been hidden.
Because there is no Node version enabled in the site that supports it atm.
Had the same issue, idk why
This comment has been hidden.
Because there is no Node version enabled in the site that supports it atm.
Expected: "8j8mBliB8gimjB8B8jlB", instead got: "Ihavespacesinmystring"
Trying to do this in Ruby...what am I missing here?
Probably your code was wrong, your current code is ok.
what do i do here, i just joined and dont know ANY lua code
D translation
Approved, thanks
For one of the tests in C, the following expected result is incorrect:
that test has been removed. please let me know if you find any other problems, thanks
This comment has been hidden.
Because there is no Node version that supports it available atm.
This comment has been hidden.
Don't raise an issue just because you believe your code works in your IDE and not here. Apparently, you don't know, so ask a question maybe.
I strongly advice you to read carefully this and not raise issues so lightly in the future: https://docs.codewars.com/training/troubleshooting/
Something more: always use a spoiler flag as soon as you post code somewhere. I put the flag on for you this time.
You must return a
std::string
, not a null terminated C-string.I seriously doubt your code returns a correct result in VSC or anywhere else.
Thanks
Don't use the null character. That's not what the kata is asking you to do.
This comment has been hidden.
you're not using the replace function properly. here's a site to see where you're going wrong
https://www.w3schools.com/python/ref_string_replace.asp
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
For SQL users, the table name is nospace
FROM nospace;
not a kata suggestion
This comment has been hidden.
Don't post solution in discourse, also not a kata suggestion!
SQL table name? seems like the description is lacking
All the relevant informations are in solution set up. If you lost them, save your code and click on
reset
.This comment has been hidden.
Not a kata issue, please don't post solutions in Discourse.
This comment has been hidden.
Kata hint != kata suggestion
This comment has been hidden.
Approved
This comment has been hidden.
Read there which Node's version allows you to use it.
failed because couldn't find table name
This comment has been hidden.
COBOL translation.
Approved, thanks
Good for beginners like me
Good learning exercise for beginners.
This comment has been hidden.
This comment has been hidden.
It is not available for the Node JS versions we are using on CodeWars at the moment. Look at the documentation and you will see. Though there exists a similar function that can do the same job easily.
This comment has been hidden.
I don't want to spoil the kata, for this reason I marked your last message as a spoiler. It's just the first word of the function you wanted to use.
I advice you to use the Mozilla documentation for JavaScript, it's very clear and complete, and gives related search items at the bottom of each page.
Apologies, I thought that by marking my initial feedback as a spoiler, it would be inherited by all further comments. Yeah, I did end up using that to solve the Kata. I thought you had seen my solution and were hinting that there was a different one I could/should have used.
No problem, glad you solved it :)
SQL translation
Approved, thanks
This comment has been hidden.
you can't use strip method because it removes spaces at the beginning and end of the string, and you need to remove all spaces, including the ones in the mid string. check this article for other methods of removing spaces in strings: https://stacktraceguru.com/java/remove_spaces_from_string#trim_vs_strip
This comment has been hidden.
I know you asked this question a long time ago, but I think it is because trim() removes leading and trailing white spaces. The Kata asks you to remove all spaces, including the ones in between strings of characters.
This comment has been hidden.
string before the call: "8_j_8___mBliB8g__imjB8B8__jl__B" string after the call: "8j8_mBliB8g_imjB8B8_jl_B" (underscore = space)
I think this is the easiest one i've done thus far.
Attempting in python and received the following result for all tests:
Log: 8j8mBliB8gimjB8B8jlB None should equal '8j8mBliB8gimjB8B8jlB'
The output is definitely a string, any ideas why I'm having this issue? I'm very new to Python so sorry if this is something really obvious.
I think you might be printing the output rather than returning it
so rather than print("your answer") you should do return "your answer"
https://docs.codewars.com/training/troubleshooting
Oops, that's definitely what I was doing. Thanks for your help!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
The updated Go translation has been provided. Contains example and random tests.
Please review and approve.
Approved, thanks
This comment has been hidden.
Please, don't post solutions in Discourse.
OH im sorry! how do i delete my comment?
Now you can't, don't worry. If you want to Discuss you solution or another one, please use Solutions and even there, mark your post as having spoiler content when needed.
R translation
Approved
This comment has been hidden.
why doesnt x.trim() work?
This comment has been hidden.
This comment has been hidden.
Because it doesn't work in Node < 15.0.0.
Thank you
My first attempt on Julia translation, please review and approve ~~
Approved, thanks
No random tests in
Added those in Lua
Awaiting approval of Rust fork with random tests. Rust version is 1.54
Come to discord @zLuki ~~
Awaiting approval of Shell Fork with random tests
@ejini战神 Ok sure!
I've copied both fork's test cases into the editor as the author is still active which blocks approval. Thanks for your time and effort !!! ^^
Just one question, why can you do that and I can't? Are you a poweruser?
I rmb you need to have 10K honor to enter the editor (6K is for approving translations, my bad) ~~ (Yes, I am)
This comment has been hidden.
'Test' is not defined...what does this mean?...it isn't showing approval or disapproval with the code tho'
This comment has been hidden.
You're using a method that is not supported by the current JS version at that time, now it should be fine ~~
This comment has been hidden.
Can someone explain me what does this result mean? expected:<8j8mBliB8gimjB8B8jlB[]> but was:<8j8mBliB8gimjB8B8jlB[ ]> I'm coding on Java.
it means> expected:
8j8mBliB8gimjB8B8jlB[]
but was:<8j8mBliB8gimjB8B8jlB[ ]>
Are you kidding me?
na, there;s space in list at end in your result
Ok thank you
This comment has been hidden.
This comment has been hidden.
Too easy :)
Class and method should be marked public. They have package level access by default.
Done
This comment has been hidden.
push
is not a string method.What Chrono79 said, let me expand:
You're given a string, and you're trying trying to push onto it. It makes sense to try to do this, but it's not quite right, you've forgotten a step!. As chrono says,
push
isn't a string method.Can you think of any built in method that would let you change string to something you can work with in this case?
Have fun!
Or you can simply use string concatenation.
I think you should focus on a built-in method.
This is just feedback.
I really enjoyed this. It's a simple enough challenge with multiple ways to achieve it (as always!), but it can be very useful to know how to do things like this.
:)
yeah, really useful. :)
This comment has been hidden.
sixteen THOUSAND coders have solved this in javascript. it is a VERY common mistake to think just because it works somewhere else that codewars is broken. you have to break yourself of that notion! this is not a kata issue, your code is wrong. just read the error messages, you're not even removing all the spaces.
thanx for the advice, I'll keep it in mind.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
In the function declaration, the second type hint is to specify return type of the function. So, it's just saying this function will return a string type value.
Hope this answers your question.
P.S. this type hinting is new in PHP 7
Racket translation
Approved, thanks
The initial "return x" is a tad confusing, perhaps changing it might make it more understandable.
Hi!
I pass the sample test and some final test but I get a waterfall of malloc related error, not sure how to interpretate them.
Thanks for any tips :)
This comment has been hidden.
This comment has been hidden.
Passed, all good :)
I would suggest giving an appropriate class name for the Java version, for example - class WhitespaceRemover.remove(String). If you have a local collection of your own kata solutions (for example all solved kyu8), it comes into conflict with other code challenges where an author has declared the same name.
resolving (seehere)
This comment has been hidden.
def no_space(x):
Scala translation available for review.
Approved
This comment has been hidden.
Hi,
Seems you're "rather new" to cw, so here are some general guidelines about the comments:
Issue
: problem in the kata itself (description, wrong tests, wrong internal solution...)Suggestions
: well, I guess that part is clearQuestion
anything else that is related to you having a problem solving a kata -> that's you, currently.When you post issues:
When you post a question: well, most of the above apply too x)
And for your current problem, did you check what are the inputs/outputs? You should have an ssertion message giving you what the expected answer is, normaly.
Closing, since it's not an issue, but that's not an end to the discussion (note tho that I don't do C or C++ myself, soooo I'm just passing by... x) )
cheers
There is an issue with this kata, the solution is good, and passes the random test. The static test is failing. You should have explained what is wrong instead of closing the issue, espessially if you don't do C/C++ yourself.
yeah, well you should know that what you're trying to do is reassign chars within the string actually passed to you... in the case of the sample test, which you can clearly see, that is a string literal, which is impossible, so your program crashes.
This comment has been hidden.
This comment has been hidden.
it states
For C, you must return a new dynamically allocated string.
in the description (which was already there before the update) nevertheless, the declaration now does showconst char *str_in
This comment has been hidden.
At least you should return a pointer to an array, of which the type is "char *".
At least you should return a pointer to an array, of which the type is "char *".
Any advvice for debuging (in C)? I am failing a test and my output matches the log.
I had the same. In my case it was because I was initializing result as
char res[size]
(wrong) instead ofchar *res = malloc(size)
(I'm new to C :| )Regardless, error message
The expression 0 is false
is really not helping...After running someone else's code through the tests, the test appears to be in the wrong. Although your code takes an argument of type "char * ", for one of the fixed tests you are passed in a "const char * ". When you try writing to it, your code probably crashes - it's trying to write to read-only memory.
In my view, the test should be changed to allocate memory, copy the argument into that memory, and pass it to your code.
the C code has been updated, please let me know if you still have any reason for thinking there's a wrong test
in simple test i had "8 j 8 /-/gmBliB8g imjB8B8 jl B" and expectation "8j8mBliB8gimjB8B8jlB" look at (/-/g) REALLY?!
This comment has been hidden.
Your functions should return in CW, and why that if?
This comment has been hidden.
OK the answer to my own question is: yes, strings in JS and TS are immutable, that is, once created, their internal state cannot be changed. Functions that operate on a string in fact return new strings. My solution would work even if I do not create a new string to compute the result.
Does your code pass the other tests?
People trying to solve the problem in "C" have noticed immutable memory being used, even though the argument type passed in is for a mutable string.
the C code has been updated
This comment has been hidden.
When reporting a problem, always state the language (when the kata has more than one).
I am using C language.
@rowcased take a look at this ^
having the same issue, trying to solve it in C. while all random test pass only this one throws a signal code 11.
as sample test it passes too. verify_fixed(no_space("8 j 8 mBliB8g imjB8B8 jl B"), "8j8mBliB8gimjB8B8jlB");
C translation kumited
please review and comment
domo!
Approved
awesome, thanks
Kotlin Translation
Please, review and approve/comment
Approved
This comment has been hidden.
Not a kata issue, it's a problem with your code, use Question label for cases like this. Don't use global vars (they keep their values between tests), and your function should return a string, don't write code outside your function, it won't run when your function is called.
Thanks, I appreaciate the feedback and have revised the code
May be a stupid question but what do you mean by 'your function should return a string'?
Your function's code has no
return
inside so your function is returningundefined
.console.log
can be used to debug, but for almost all katas in Codewars, your function should return a value. If you're completely new to programming I suggest you try doing some free online course/s first because although there are beginner katas here, most assume you have a certain knowledge and won't explain the very basics.Well i appreciate you taking the time
I've been coding about a week and wanted to solidify my learning. A friend suggested here
This comment has been hidden.
You're not returning anything.
Issues are kata-related, for help with the code there's
question
tag.Python implicitly adds a "return None" to the end of every method. If you don't specify a return value, your code returns None.
I am unclear on the first test case --- it seems to not validate with the entire string with no spaces, but rather a non-repeated instance of the string with no spaces? Assert::That(no_space("8 j 8 mBliB8g imjB8B8 jl B8 j 8 mBliB8g imjB8B8 jl B8 j 8 mBliB8g imjB8B8 jl B"), Equals("8j8mBliB8gimjB8B8jlB"));
Why isn't the actual solution to that 8j8mBliB8gimjB8B8jlB8j8mBliB8gimjB8B8jlB8j8mBliB8gimjB8B8jlB?
Am I reading the problem incorrectly?
If you're talking about sample tests, the first one is this:
Ugh, boneheaded mistake - I had somehow copy/pasted that test string over and over into that test window by mistake, and then tested with the parameters I showed above.
Thanks for telling me that, it would have driven me crazy =). My solution passed fine now!
@A.Partridge Nice Kata Pete .. Enjoyed for sure .. Regards .. Zizou
:)
this was a good exercise
TypeScript Translation submitted.
Approved, thanks
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Ah now I get it thank you. And sorry, I thought the comment section was only available from the solutions.
This comment has been hidden.
Not for an 8 kyu kata.
This comment has been hidden.
This comment has been hidden.
just cant run the code help please
Please post your code and mark the comment as spoiler, and I'll do my best to help
This comment has been hidden.
i am a chicken !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
已阅(此处省略三千字)
This comment has been hidden.
Your code works for me. Make sure your return statement is outside of the for loop otherwise it will return at the end of the first loop.
This comment has been hidden.
if x[i] != ' ': is not right if not x[i].isspace(): is right
thank you~
Actually, they work both the same, but .isspace() is better.
CoffeeScript Translation kumited! Plase Accept :smile:
Done, thanks!
C# translation kumited <a href=https://www.codewars.com/kumite/58e338f789419f5412000082?sel=58e338f789419f5412000082>here, check it please ;)
Approved, thanks
This comment has been hidden.
You need to return x, ya noob (with
return x
). Otherwise the function call returns nothing and therefore "undefined" is returned by default.Functions behave like mathematically functions where an input is put in and an output is received - shit is happening in the function but nothing is returned as an output (function must return a value so that it can be checked for equality). All Katas on this website work like this.
Legend. Thanks! Wicked explanation brother ;)
Crystal translation kumited :)
Approved :)
Hi, I passed the run examples but not the attempt. Is there something wrong with my solution? thanks Sorry if this is a dumb question, still a noob.
Philip, try using something like console.log or equivalent when you run the tests, this should show you which ones are failing and make it a little easier to work out.
Thank you, will do.
Hi, is there any issue with my Haskell translation? If not, can you please approve it? Thanks, suic
Hi Suic, apoologies must have missed the notification. Approved now
No worries and thaks for approval :)
This comment has been hidden.
And Python version just served :)
Approved, sorry for the long delay!
PHP Translation Kumited - please accept :D
approved
closing suggestion
Ruby translation available.
Approved