Retired
Remove Zeros (retired)
6,529 of 6,542AustinBrunkhorst
Loading description...
Arrays
Sorting
Algorithms
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.
This kata is a candidate for retirement as it relies on contraints which are not enforced well, and are very difficult to enforce. Please join the discussion and share your opinion on whether this kata should be kept, or retired: https://github.com/codewars/content-issues/issues/167.
My first 4. But it probably too easy for a 4. There's even 7kyus harder than this. Anyway, enjoyed it.
i got only 1 false mixed test but i can't see the input so i don't know what the problemis
Expected: '[1,"0","0","0",0]', instead got: '[1,"0",0,0,0]'
Read this: https://docs.codewars.com/training/troubleshooting#print-input and use
console.log
thank you for help
You're welcome.
crazy 4kyu
wont even let me use shift and pop.. darkness
This comment has been hidden.
Yes, it's a Node specific issue, and not really a kata bug.
You assume that elements which are not meant to be moved will stay on their original relative positions, which is not the case with
sort
in Node 8.sort
can, in case of Node 8, reorder elements in any way as long as the final ordering satisfies requirements of your comparer. With input of[2,0,7]
it's perfectly fine to get the sorted result of[7,2,0]
.a good kata, but i think it would've been better if it was 5kyu or 6kyu
Ranks of approved katas cannot be changed, so please don't complain about that and enjoy the cheap points.
Weird kata. But I had fun solving it.
This comment has been hidden.
Oh and if its more likely that its an unterminating while loop causing the problem then please do bring it up
Id just like to ask what exactly temporary arrays and objects are
For objects, see there: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
With temporary arrays, I assume the description means you not create any other and should use only the input array.
A temporary array/object is a place for you to store values and then stitch them together again.
I assume the kata wants you to implement a sorting algorithm... unless it thinks comparisons should also count as a temporary object, in which case, I am at a loss.
This comment has been hidden.
You shouldn't use for...in with arrays https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#array_iteration_and_for...in
Not a kata issue.
Got it thanks!
Confusing description. And it definitely looks like 6
This comment has been hidden.
Use something like bubble sort but make it sort not-zeros and zeros.
This comment has been hidden.
It's already there:
Clarification of what types are considered zero would really make the instructions less ambiguous. I had to forfeit eligibility to see the test suite because I could not get the proper order for all falsy values that are expected to return
[1, null, '5', '2', 8, 6, null, false, '0', 0]
. This was the only test that failed. Without giving anything away with respect to the test suite or solution, I'll just mention that the input array's falsy values do not appear in that order, but those of string or number type that loosely equal zero do. I don't see why it should be left to each user to figure that out.Isn't that enough?
it's too easy for 4kyu
Can anyone tell me that eror cause? log: [ 1, 2, 52, 7, '3', 1, 0, 0, '0', '0' ] Expected: '[1,2,52,7,"3",1,"0",0,"0",0]', instead got: '[1,2,52,7,"3",1,0,0,"0","0"]'
When I run removeZeros([1,2,52,7,"3",1,"0",0,"0",0]) in my IDE it returns [1,2,52,7,"3",1,"0",0,"0",0]. Where did I go wrong?
the order of your zeros is wrong. for example, if we have the input array [1,2,"0",4,4,0,1,4,"0",2] then the output should be [1,2,4,4,1,4,2,"0",0,"0"]. If the zeros in the back are in any other order, it doesn't work. For example the output [1,2,4,4,1,4,2,0,"0","0"] would be wrong.
I konw why that I'm not thinking about the order of zeros!
Are you really??? It says that my answer incorrect cause of order!!!
Expected: '[7,2,3,4,6,13,78,19,14,0,0,0,0,0,0]', instead got: '[7,2,3,14,4,6,19,78,13,0,0,0,0,0,0]'
Yes, really.
Please, read the description again.
This comment has been hidden.
When I run
removeZeros([1,null,"5","2",8,6,null,false,"0",0])
in my IDE it returns[1, null, '5', '2', 8, 6, null, false, '0', 0]
. When I runremoveZeros([1,null,"5","2",8,6,null,false,"0",0])
on Codewars it returns[1, null, '5', '2', 8, 6, null, false, 0, '0']
.Eh?! Help pls :D
false == 0 consider it. "Zero elements are defined by either 0 or "0". Some tests may include elements that are not number literals."
in older javascript versions,
Array.prototype.sort()
was not guaranteed to be stable.very bad kata, description is not compliant to actual solutions big dislike lol
shit kata lmao
yea..
wait,does it count as temporary array if i pass my array into another function?
I was afraid of that too, that's why I didn't create other functions.
No random tests
This comment has been hidden.
Wow, how did you figure it out?
By looking at the sample tests, I saw that the tests are really weak :)
This comment has been hidden.
Yeah, It's kinda sad that people don't cheat not because it's not allowed, but because they can't.
one of my favorites!!
this is too simple for 4 kyu, but good kata anyway!! thanks
This comment has been hidden.
Good job, now try to solve it again with no temporary arrays :)
but it's solved :) my answer is passed the test..
yes, the tests in this kata are very bad. almost as bad as your ability to read the instructions
too easy for 4kyu..?
Cannot change rank.
Also, there's a 5 kyu without restrictions but otherwise the same.
Nope, but of course it would be too easy if you cheated :)
Node 12.x should be enabled.
It seems to me that arrays need a medium and entropy will cause all mediums to fail in time, making all arrays temporary in the long run. Which makes it difficult to use the input array, if i'm not allowed to use any temporary array. At least that is my excuse for not understanding the nature of how computer folk define temporary.
At first I solve this kata without using any array.prototype and object.prototype methods, but I used JSON.stringify. All tests were passed but stringify() failed cause it's prohibitted. WHY? It isn't array or object prototype method! Description and tests to this cata isn't correct! But it was funny, when I solve it then using two temporary arrays and spread operator))))) What a f... going on with this tests!?
Just finished the Kata after a bit more than 40 minutes, and to be honest. I don't feel like this Kata belong to kyu 4. Should be more about 3 or 2 with all the constraint inside of it. Also, a lot of answer used arrays and methods linked to Arrays, I don't know if people trying this kata should do it or not, it's complicated for not much.
In solutions people use arr.length(which is part of Array.prototype) and also in description it was nowhere mentioned about replace is prohibited. Also clearly mentioned no temp array but in many solutions I can see temproary array being created. It seems kata is not properly described.
arr.length is a property of Array.prototype and the kata prohibited Array.prototype methods. And I agree with you, so many solutions are using temp array, the worse is that they are marked as clever...
nice kata! not too hard but makes you think.
Honestly the rules just make the kata artificially a little harder. Community had fine may way to circumvent it. And even if you play it fair they are not that hard to reproduce. Definitly not a 4kyu.
I was a bit confused about not using temp objects. It made me think I couldn't use variables at all. It's clear from the other solutions that I could have very easily used variables sooner and solved it immediately.
Exactly
Not a huge fan of the unecessary (and a few unstated) constraints. I get the purpose, but not sure how much value that brings. I geuss I learned something.
This comment has been hidden.
Not possible!
This is free points.
So i've solved this kata and learned a lot in the process. However the solutions have been withheld and it's saying I have not solved it.
This comment has been hidden.
This comment has been hidden.
It's asked not to use temporary arrays or objects; Primitives are fine :)
^Yeah, but he's right. Many solutions use temporary arrays.
This comment has been hidden.
The constraints were meant to limit the space complexity to constant which is definitely useful in memory-constrained platforms such as embeded systems or even in a large scale data streaming application which can't store everything in the memory.
This comment has been hidden.
Won't work.
You could try to solve it.
Great kata! I'd love to know how you disabled prototype methods in your test environment.
This comment has been hidden.
One of the most exciting katas to have solved. The best thing is - you are better off not knowing Array prototype methods to do it.
This comment has been hidden.
The zeros must come in the order they appeared in the original array. There is no specification for strings or integers first.
This comment has been hidden.
Had some problems with
false
, but it is ok now. Good kata, I liked! :)I had also issue with false.....
It's a bit easy when using destructuring to swap array elements...
Please point out that the JOSN.stringify is not allowed also.
I think the kata description should be updated to say no regex. I originally wrote a solution using String.prototype.replace (which isn't an Object or Array prototype method) only to find on submission that replace isn't allowed.
I enjoyed this kata, otherwise.
You are NOT allowed to use any temporary arrays or objects.
I'm not entirely sure what it means exactly by not allowed to use temporary objects. Am I allowed to use temporary vars to store
Number
? (e.g.let x = array[i - 1]
)Anything which is not an object type such as maps, arrays, object literals are not allowed. You can create variables of primitive types such as numbers or may be even string
I broke my brain )))
awesome kata)))
However, you can still use the methods of an array, and can't resolve with the Regex.
You can use monkey patching method to built-in objects.
I posted to the gist, and you can use it.
My two cents for this kata are:
it is in bad need of renaming. Its current name ("removeZeros") is completely misleading as the intention of the process is merely shifting "zero" designated elements to the end of it. "shiftZeros", "moveZeros" or "trailZeros" would be way more appropriate names.
it clearly does not belong in the 4kyu league. It should be at least 5 or 6. It is way too simplistic, even with all the non-sensical restrictions - like not using built-in language features (i.e. Array.prototype functions), reason of which brings us to:
most of the constraints do not make any sense, do not benefit the kata in any way, and more importantly, cannot be strictly asserted by tests. Conformity is at the mercy of any warrior's willingness or morals.
I feel this kata didn't help me advance in any way
I feel the same way. The artificial constraints make this an anti-kata, or a lesson how not write Javascript.
+1
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
there are lot of bugs in this kata, remove it
This comment has been hidden.
This comment has been hidden.
Can you help to check if something is wrong? I always get 'Code timed out' even my code passed a lot of tests ...
Your code is running time is not more than 10 seconds, it shows that your code needs to be optimized^-^!
Very restrictive without any word of it in the description. I'm not even sure why some of the restrictions are there. (
.toString()
?!)Well, I managed to do it without using temp objects but also without moving each zero separately. Not sure if that was what was intended, but I'm kinda proud of my hacky way round it! ^^
I made a note indicating the restrictions in both the description and sample code comments. I'll address it better in the description to clear up any confusion.
This kata was designed for a challenge given the restrictions. The solution is very simple using language features and/or temporary arrays. What did you intend to use
.toString()
for?I thought you weren't allowed to use arrays? If I could use arrays, it would be very simple. But I can't use arrays, so it's kinda unnecessarily complex , I feel. A nice challenge, but there were just so many hidden restrictions and caveats that were not even mentioned in the description.
I was going to use
array[i].toString() === "0"
to check for zeros. Not that efficient, but just to get it working.In my opinion, you shouldn't add a load of restrictions and limitations unnecessarily, especially without telling the coder about them. The order apparently matters with the string- and number-zeros, but this wasn't mentioned either.
You aren't allowed to use arrays. What I meant by
The solution is very simple using language features and/or temporary arrays
is that without the restrictions I've set in place for this kata, finding a solution is not very difficult.I'm under the impression you did not clearly read the description of the kata. There are no "hidden restrictions and caveats". I've clearly stated -
and
That's the point of this kata - to raise a challenge. A subjective feeling shouldn't be the cause of reporting a minor issue.
I did read the description correctly, but assumed you meant actually useful methods for this kata, or maybe even just those on the Array object. The Object methods aren't that useful for this, and if people want to make some convoluted work around with them, then it's just as challenging and creative anyway, right?
As far as I can see,
.splice()
is the only relevant method you might use for this kata, so you could just block that instead (and maybe concat and slice for good measure). If the coder wants to use other, not directly helpful methods because that's just the way that want to do things, then why not? It should still preserve the challenge, I think.I restricted all prototype methods to be consistent - if you don't need it, then it shouldn't be a problem. This kata is not in seek of a creative solution but rather one for a challenging problem.
I'm assuming you're the other user to flag a minor issue - like I said before, is there anything that's actually an issue other than your opinion on the problem?
I guess not. I'll give it a "Ready", but really this kata could be more enjoyable to code for. I have written kata in the past that have received critique other than literal objective problems. Heeding such feedback or giving good reasons you wish to keep things as-is is a nice way of saying thank-you to the CodeWarrior who took the time to think about how to improve the kata. Such behaviour makes CW a place to find interesting, well-written kata to help people improve their craft and expand their ideas on how to solve different problems. But I guess you just want a "Ready". So you shall have it.
This comment has been hidden.
@parabola949: That's a variable. It contains one value, and no
Array
/[]
orObject
/{}
is instantiated. The restrictions are there to prevent you from doing something like the following:Since your comment also included parts of a solution of the kata creator, I marked it as spoiler.
It's quite amusing that the comments given as part of the Solution Setup makes the test fail. I had similar problems trying to figure out how to stop people using built-ins. I resorted to setting all prototype methods to null, so it would throw an error that way.
I can't really figure out how we're meant to solve this kata, though... Without even splice, or using temporary objects, we have to move all the items along every time we want to take out one of the zeros; is that right? Or a I missing something?
Yep, that was a bug which has since been fixed haha.
As for finding a solution - you can use temporary values, just not auxiliary data sources such as an Array or Object.
You are correct when saying you need to move all elements each occurrence of a zero.
Okay; that's fine then. Just wanted to make sure I wasn't making a whole ton of unnecessary work for myself ;P
I had word 'finding' within my comment block and this made my code fail with the following message: 'Array.prototype.find is prohibited'. I guess it should be allowed to use this word inside comments? Other than that - great!
Thank you for pointing that out! I made an escape error in the regex validation of the source code. I also added comment stripping so it won't be an issue anymore.
It's too bad this is the exact same thing as this kata, only with the limitation to not use built-in language features or temporary arrays.
It would be nice if it had something more to it to differentiate it better, but I suppose it's technically different.
I completely see where you're coming from, but I feel that without the use of prototype methods, it's a completely different problem, as expressed in the comments of the other Kata.
I think this is a good exercise . Similar concept to other katas, but the extra constraints make it more fun.
This comment has been hidden.