5 kyu
Moving Zeros To The End
77,805 of 192,073xcthulhu
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.
Would be appreciated to leave some detail about what the full test suite tests in the kata description. Even if it's only a statement that says to expect that the input could contain any data type.
Great kata, but it is too easy for 5 kyu :)
This comment has been hidden.
you shouldn't post code like that; anyone can see it.
I added the spoiler flag to your comment
Hi I checked your code gives wrong result for this sequence [9, 0, 0, 0, 9, 1, 2, 0, 1, 0, 1, 0, 3, 0, 0, 1, 9, 0, 0, 0, 0, 0, 0, 9] can you check locally
your solution has a bug that incorrectly handles four zeros in sequence example input data [9, 0, 0, 0, 0, 0, 9] your code will return [ 9, 0, 9, 0, 0, 0, 0, 0 ]
I think this testcase is wrong
expected [ 'a', 'b', null, 'c', 'd', 1, 1, 3, 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ] to deeply equal [ 'a', 'b', null, 'c', 'd', 1, false, 1, 3, [], 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
In the first array there is no 'false' however the second array has a false for some odd reason. There is also not a square bracket in the first array, however there is one in the second array. Can you help me out ?
There is a
false
value in that input as well as[]
(an empty array). The actual input for that test is['a', 0, 0, 'b', null, 'c', 'd', 0, 1, false, 0, 1, 0, 3, [], 0, 1, 9, 0, 0, {}, 0, 0, 9]
.expected [ 'a', 'b', null, 'c', 'd', 1, 1, 3, 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ] to deeply equal [ 'a', 'b', null, 'c', 'd', 1, false, 1, 3, [], 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
means that your code returned[ 'a', 'b', null, 'c', 'd', 1, 1, 3, 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
, but it should have returned[ 'a', 'b', null, 'c', 'd', 1, false, 1, 3, [], 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
. The message you copied does not mention the input to the function.This problem is caused by a bug in your code. For future reference, the
issue
tag is meant to be used when there is a problem with the actual kata. You can use thequestion
tag if you need help with your own code.As to the reason this is happening, make sure your code isn't confusing
false
and[]
with0
.0
,false
, and[]
are all falsey values, so it seems like your code might be confusing them.move the zeros to dart Translation Dart
too easy, it should be 7 kyu
Ranks cannot be changed as of now, especially for old katas like this one
This comment has been hidden.
res = lst
does not create a copy and does not prevent changes of the original input list. If you create the copy correctly, your solution will work.The issue is not as much with tests, but more with spec.
This is not even an issue with spec, the kata generates the expected answer before passing the argument to the user's function. In this case, the user is mutating the list as they iterate through it, causing issues. I'm closing this issue.
Hey there! This is a great kata, but I, personally, believe that the kyu for it should be decreased a bit, as it is a bit less complicated/simpler than most other 5 kyu challenges. Other than that, though, it's a wonderful kata! Keep on creating :)
Ranks can't be changed :(
Would it make sense to ask in the
Details
to solve it in place without allocating additional space for a copy of input? So the problem is really5kyu
.Nim translation
Can somebody review and approve it, please.
"expected [ 1, 2, +0, 1, +0, 1, +0, 3, +0, 1 ] to deeply equal [ 1, 2, 1, 1, 3, 1, +0, +0, +0, +0 ]"
the log in my console when i hit "test":
test Log [ 1, 2, 1, 1, 3, 1, 0, 0, 0, 0 ]
wtf is wrong lol
It seems you found your mistake and passed the kata.
bro i am facing the same error :/
Codewars problems are now not that good and properly made. I always get this unexplainable condition added at the end of testing.
very good kata !
I agree
It was easy for me even tho I'm 7kyu. The 6kyu kata here: https://www.codewars.com/kata/search/my-languages?q=&beta=false&order_by=satisfaction_percent%20desc%2Ctotal_completed%20desc was also easy. While most of the 7kyu katas I did were hard for me.
This comment has been hidden.
yes, your code works wrong for that test case.
.. go fix it? x)
if you think the test case is wrong then I don't think you looked at the test case, which makes me really confused - why wouldn't you even look at it before posting about it?
I will try to review it again, because I haven't been programming for a long time, it's very possible to make a mistake, but when I do a test in my editor with the second test array, I get the correct result, anyway, thanks for the answer.
I fixed it ։)
I don't understand what is wrong expected [ 9, +0, 9, 1, 2, 1, 1, 3, 1, 9, +0, +0, 9, +0, +0, +0, +0, +0, +0, +0 ] to deeply equal [ 9, 9, 1, 2, 1, 1, 3, 1, 9, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
+0 what is this?
The first value there is your answer, and you can see there are more than one 0 not at the end. Probably you're mutating the array at the same time you run through it, skipping values.
About what +0 is, you can see that's 0, don't mind the + before it, it's probably chai adding it in the assertion.
Got the same error
Actually,it's a easier than 5kyu problem, 7ky is enough
Yeah
I think even 8 kyu
So, this problem actually easy for 5 kyu. But if you tried to solve this
O(N)
and no extra memory, it feels like 5 kyu.expected: [true, "9", 8, "8", "8", nil, 1, 6, "2", 7, 3, nil, 5, true, nil, "1", "1", "0", "8", "1", 2, "5", "8", [], 0, 0]
does the test includes other data types?
A lot of examples are wrong, this site is awful
Like what? Your issue report is unhelpful if you want something fixed. State the language, the values, why you think they're wrong.
Btw, your code is wrong, not a kata issue. Print the input and debug your code. It fails tests like this one:
Before creating a kata issue, please look at how many times it was succesfully completed:
Truee getting tired of pasing the test then when trying to attemp it suddenly has different conditions provided. +0 is not included in the test only 0.
@Carl98K 0 and +0 evaluate to the same thing, you wouldn't be able to detect a difference as no difference exists between two of the same value. The problem is that your algorithm is flawed - you are reading from and writing to the same object without taking care to ensure that the writes don't affect the reads. Like peeing upstream and then getting it in your drinking water.
-0 would be another matter. that is a distinct value. but I don't think those are included.
Groovy Translation
Agree that this should be a 7 or 8 kyu. Solved in a language agnostic way but I imagine many languages have sorting functions that can essentially one line this.
Super easy kata. Should be an 8 kyu
Why is this a 5 kyu instead of an 8 or 7 kyu?
Yes, it is overranked, but it's because it's very old (from 2013). However, it definitely isn't 8kyu. Re-ranking it at this point would be too costly (would require loads of recalculations), so for now... just take the free points and move on :P
Ohhh makes sense, yea I completely forgot this website is that old.
This comment has been hidden.
Not a kata issue, you are removing and checking zero equality at the same time, which can cause some values to be skipped.
Ignorem isso, erro meu
I solved this kata in C and Rust, and I have a question. Why does the function in C mutate the array in place, but in Rust it requires to create a new vector? In Rust, we can use mutable slice to change data in place as well:
fn move_zeros(arr: &mut [u8]) { todo!() }
translations should try to be idiomatic and use the datatypes/techniques that are usual in their language. output parameters and programming by mutation are much more common in C than in other (higher-level) languages
This comment has been hidden.
Can this be moved to Kyu 7?
Can this be moved to Kyu 7?
Lua translation!
This comment has been hidden.
nice kata, but this is too simple for 5. Maybe 7?
I got stuck in this test case:
which is clearly wrong...
I can't tell what language you are using, but I would suggest checking to see if your code mutates the input (since that can be reflected in poorly written tests).
If so, please let us know so it can be fixed (and also: don't mutate the input)
Thank you for the response.
I used C and my solution does change the input inplace as the output type signature is marked as void.
your code contains undefined behavior, your
while
loop will happily iterate past the end of the array and overwrite arbitrary memoryShould be 7 or below tbf
Fine Kata for Golang learner like me, but why 5Kyu? :) Anyway thanks a lot :)
Example of incorectly failing test for javascript (please see the empty array in the right) expected [ 'a', 'b', null, 'c', 'd', 1, false, 1, 3, 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ] to deeply equal [ 'a', 'b', null, 'c', 'd', 1, false, 1, 3, [], 1, 9, {}, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
The test is fine, your code is wrong. It is converting empty arrays into zeros.
You are right, I realized it later and I was unable to delete my comment :) Thanks
Did an earlier version test for False not counting as literal 0, or maybe it was mentioned in the directions? I don't see that, but some of the solutions account for it
The tests for Factor 0.99 try to
USE: math.ranges
, which is renamed in that version toranges
, so the tests won't run successfully.Fixed, thanks for reporting
Can't undertand the behaviour of 0.0 - why should it be 0, but 0.0 in result array.
it should be 7kyu
I couln't agree more, too basic
This comment has been hidden.
Print the input to console to figure out for which test your code fails. It's probably a case you didn't test in your IDE.
OP solved it, closing
When I do it in my ide all 0 goes to end but here in my attempt, one zero is less at the end in random test case.
Not a kata suggestion, print the logs and read it carefully , do not misinterpret
0
as 0This comment has been hidden.
Not a kata suggestion, please don't post solutions in Discourse.
Good kata but a little bit overrated. Guess 6 is a good enough :)
Could you please tell me what is wrong with my solution? When I run it in Chrome or Mozilla everything checks out...
Your solution fails to handle consecutive zeros.
Much obliged!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please do not post solution code in the discourse.
This is too easy.
Two Go tests are not written correctly when they have already changed
could you be more precise, please...?
When testing on go, my program gives the correct answer and writes that it is not piavilno because in the codewars test, not all zeros are at the end
your code is not correct, for example for
{1, 0, 0, 2}
it returns{1, 0, 2, 0}
instead of{1, 2, 0, 0}
python new test framework is required. updated in this fork
Approved
uhh. it already was using that though.
.. ??
This comment has been hidden.
Use code formatting when posting blocks of code.
Not a kata issue. Your solution is incorrect.
try to debug it using
print
, and see what happened to the list when you iterate and remove something from it.This comment has been hidden.
I think this question is too easy for a 5 kyu. Perhaps a 7 kyu.
In PHP the second test includes 0.0 in its values: $this->assertSame([9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0], moveZeros([9,0.0,0,9,1,2,0,1,0,1,0.0,3,0,1,9,0,0,0,0,9]));
the digit 0.0 are counted as a zero but expected to be a single zero after moving to the end. All tests will pass if a single 0 is added to the end for any digit that evaluats as 0 (including 0.0).
I think it was tested with a weak comparison
assertEquals
, but as of right now changed (don't know when?) to a stricter oneassertSame
, and change only the method not the expected value (making some user solutions invalid). Because of that, I guess we can assume that all zeroes value (wether integer or double) needs to be converted to integer 0 ?Your explanation makes sense, but it is fairly easy to spot the mistake when writing or changing the tests. If all 'noice' is removed the test is trying to assert that 0 is the same as 0.0: $this->assertSame([0], moveZeroes([0.0]));
As you say, at this moment all zeroes must be converted to integer 0 or the tests with non integer zeroes will fail. It does add some interesting complexity to the kata that you have to find different kinds of zeroes and move them, but it is also not clear in the instructions if you have to keep the order of your zeroes when moving them to the end.
This comment has been hidden.
Not a kata issue.
[ 9, +0, 9, 1, 2, 1, 1, 3, 1, 9, +0, +0, 9, +0, +0, +0, +0, +0, +0, +0 ]
is what your code returns while[ 9, 9, 1, 2, 1, 1, 3, 1, 9, 9, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0 ]
is the expected answer. Read this for more info on troubleshootingThis comment has been hidden.
All Test Cases (except one) for Go are incorrect.They are not presserving order of not zeroes values
Please print the input too. With only that Information the only thing we can see is that your answer is wrong.
This is details of the kata:
It has line
preserving the order of the other elements
.Here is a test that codewars runs. It's not my result it is INPUT and OUTPUT of codewars test:
Look at value with index
2
. Input have8
and Output have7
. This is wrong according to the task.No, it's like this:
To see the input, print it: https://docs.codewars.com/training/troubleshooting#print-input
Edited
Sorry. Looks like I somehow change it. I found error in my code and
Attempt
tests are now pass. Thank youI'll close this then.
Doing this in C, passed all sample tests. Then did it on Random Tests and it crashed on the second one with:
"Test Crashed
Caught unexpected signal: 6"
"STDERR: free(): invalid pointer"
I checked the inputs from the random tests to see if my checks just didn't catch something but it seems to be fine. I also checked my outputs to see if they weren't doing anything weird and it seems to be fine as well.
I originally assumed it crashed on the end of the first random test but it still executed code after the array mutation. The error seems to appear either after return from the first random test or immediately after the second random test is sent in because it wouldn't even execute the first command which was just a print command so I can't even check if the test inputs are the problem or not.
Na that's you. Please don't create issues without having identified the cause. Even more so for C where this is the sort of mistake you should expect to make.
Yeah, apologies
I got confused on how the logs between fixed_tests and random_tests worked and assumed they were tested sequentially rather than parallel
Making me assume that there was something wrong with random_tests if fixed_tests still passed.
It still did but was already wrong from first execution rather than my assumption of second execution so I used comments to pinpoint where I got the error and it works fine now
Even made me realize I had 2 lines that wouldn't be relevant anyway
you're still reading outside the array btw.
just because the answer is correct doesn't mean you don't have memory errors. running it with -fsanitize=address might catch it though.
any test case wrong check pleas. input array and result array do not match input array Array ( [0] => 9 [1] => 0 [2] => 0 [3] => 9 [4] => 1 [5] => 2 [6] => 0 [7] => 1 [8] => 0 [9] => 1 [10] => 0 [11] => 3 [12] => 0 [13] => 1 [14] => 9 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 9 )
test array in test case ( 0 => 9 1 => 0.0 2 => 9 3 => 1 4 => 2 5 => 1 6 => 1 7 => 0.0 8 => 3 9 => 1 10 => 9 11 => 9 12 => 0 13 => 0 14 => 0 15 => 0 16 => 0 17 => 0 18 => 0 19 => 0 )
This comment has been hidden.
This comment has been hidden.
Thank you for your help.
This comment has been hidden.
Look at it in this way: If the array is empty, is there any 0 in the array before a non-0?
If the answer to that question is no, you don't have to do anything to the array if the array is empty.
it is 5kyu if you solve it by altering the existing array, and not creating a new one
This comment has been hidden.
Sometimes you have to scour through the error messages, but here you go:
use of undeclared identifier 'move_zeroes'; did you mean 'move_zeros'?
too easy for a 5 kyu it is a 7 or 8 kyu level
Wait, in the description it says stuff like "a" and false indicating an object() array. But in the code it takes an integer() as argument. It would make it a bit harder actually, which cant hurt this one.
The description is for all languages and you're talking about, which one?
VB. I dont know if other languages can have arrays of different typed elements. But I dont think any language has "a" as an integer.
Javascript, Python, PHP, and every other not strong-typed language can, and obviously "a" is not an integer. But, Python version for instance only uses numbers, I haven't checked all languages (and probably won't do it), but it looks like javascript version is the one that uses mixed data type and its codeblock is the default example in the description for any other language that doesn't have its own.
This should be 7 or 8kyu tho
This comment has been hidden.
Does anyone know if it mattered if I made a new array insteadof altering the input? If it didn't then they kyu for this should be atleast 7, 6 at a push
It's maybe 6kyu. So easy
This comment has been hidden.
No, your code is wrong and it skips values. Not a kata issue.
This comment has been hidden.
Try logging
x
at the start of the loop. Run it, and then see the log. You'll see why.This comment has been hidden.
it is because +0 === 0 returns true. you don't want to select that
Can you elaborate on that? I get that it equals true but how would that impact the code if it just moves it to the end?
Your code skips over some values. When you relocate array items like this, the other items are reordered. If you console log the result for the errored test you will see not all 0 are at the end.
Commenting on what diannedejesus implies: You would always have to decrement i at every iteration of the loop.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
No, your code is wrong.
Also, please use appropriate formatting when posting code (code blocks).
У меня сделано правильно, но ничего не работает. Что то вы напутали. Даже пытаться разобраться не буду. Я уверен на сто тысяч миллиардов миллионов процентов, что я прав. Исправьте ошибку.
Upd: Посмотрел решение, у меня такое же почти(Я не использовал тернарный оператор). У меня пропадают false в ненкоторых случаях. Upd2: Добавил третий знак ровно, всё заработало. Бред. Так сказать, приношу свои извинения. Но по сути я всё равно сделал правильно.
Во-первых, комменты лучше писать на английском, так больше вероятность, что кто-то Вам ответит :) Во-вторых, я так понимаю, Вы решали эту задачу на JavaScript. Есть разница между строгим и нестрогим сравнением. Для данной задачи нам необходимо именно строгое.
Should be 7 kyu lol
This comment has been hidden.
Kata 5 ? really
File "/workspace/default/tests.py", line 7 [1, 2, 0, 1, 0, 1, 0, 3, 0, 1]),.
^ SyntaxError: invalid syntax
Backup your code, click Reset, paste it and try again. You have messed up the sample tests. Not a kata issue.
This comment has been hidden.
Hi, my code works but depend of the length of the table int, i have a "Test Crashed Caught unexpected signal: 6" "STDERR free(): invalid pointer" Exemple : For "int arr5[] = {0, 9, 5, 4};" that don't work but For "int arr5[] = {0, 9, 5, 4, 4};" that work. Do you have an idea where is the problem ?
Scala.
Is it an oversight that the types of the lists aren't specified in the solution setup, or is it deliberate?
it is an issue ;-)
I don't think that it cousts 5 kyu
same, learnt python yesterday and finished this in 5 minutes
NO random tests in CS (at least)
Description should be language-agnostic
Should mention that whether "0" is considered as zero, since a lot of solutions in various languages do not consider this part, but somewhat passes the tests.
Ruby
snake_case
It doesn't have to be, and this is up to every programmer's preference.
The Ruby Style Guide does suggest putting method names in
snake_case
, but this is only a suggestion.Negative numbers are missing from the input in at least several language versions. Is this needed? If not this constraint should be removed; random tests in different languages are doing their own thing in deciding whether negative numbers should be included in the input.
In Python returns that bullshit:
Traceback (most recent call last): File "/workspace/default/tests.py", line 3, in Test.describe("Basic tests") NameError: name 'Test' is not defined. Did you mean: 'test'?
Click Reset.
Why not to explain that we should move only zeros as a number? Stupid kata
Feels like 7 kyu kata
This comment has been hidden.
A problem with your code is not a kata issue. Use question label next time.
You're changing filtered there, that's used in your loop exit condition.
nice
ok guys I see a lot of controversy and kind of I'm starting to feel a bit frustrated with this kata. pls someone explain to me this. since when this is correct test result ? [ 9, +0, 9, 1, 2, 1, 1, 3, 1, 9, +0, +0, 9, +0, +0, +0, +0, +0, +0, +0 ]
It isn't, you're probably misreading the error message and that's what your function wrongly returned, not the expected value:
This comment has been hidden.
This comment has been hidden.
Your code skips values, that's why it fails. Don't mutate the array while you iterate over it or do it but in another way.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
it's not sorting properly for some tests. you can log the input to the console to see which test you're failing.
also, you are not supposed to call the function explicitly, the tests will do that for you
p.s, please mark your comment as spoiler if you are posting code snippets. and, this is not a kata issue, please use a question tag next time
This comment has been hidden.
This comment has been hidden.
old kata == easy kata
too easy for 5 kyu. too 15.55645 secs. lol.
I think many people didn't understand the kata and kata's description. I think in this kata id of lst must be the same at the end of function. So, most of all solution is wrong.
I just solved this kata! Thank you.
it's exactly 5 kyu?
This comment has been hidden.
For those that are interested in a possible O(n) solution, what I did is a pretty rough example. Not the prettiest or optimal but should be time efficient.
This comment has been hidden.
In Python, the boolean is an extension of the integer type. Therefore, without checking type, False == 0 in Python. Checking the type of the element ensures that only 0s, but not Falses, are being moved.
Very helpful!
This comment has been hidden.
The Scala translation doesn't provide a correct function signature in the solution set-up:
It should be:
def moveZeroes(lst: List[Int]): List[Int] = ???
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#print-input and print the input using
console.log()
. Also, you can use pythontutor to visualize what your code does step by step.Something wrong! My code is working, but the tests are adding extra 0 after results, please fix it. And don't tell there is problem with my code, because I've checked it with the same tests in console and it's working, but kata sais that it's wrong! It's bad I can't send screenshot here
Your current code works and you passed the kata, so I don't know what you're talking about.
Yeap, I've passed it, but because I used another method, but first method also was working( How I see there is some particular conditions fo writing code for pass it
Read this: https://docs.codewars.com/training/troubleshooting/#post-discourse and post the code that didn't work so I can check what's wrong with it.
hi there. i can't understand in what is my problem. In instruction of task There isn't anything about "[]","{}"have to be in the end of arr. What's wrong?? and so, in attempt i have a bad result, cause expected [ 'a', 'b', null, 'c', 'd', 1, 1, 3, 1, 9, {}, 9, 0, 0, 0, false, 0, 0, [], 0, 0, 0, 0, 0 ] to deeply equal [ 'a', 'b', null, 'c', 'd', 1, false, 1, 3, [], 1, 9, {}, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
This comment has been hidden.
That's a problem with your code, not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting. Don't mutate the list you iterate through, you'll skip values like that. Use pythontutor to visualize how your code works.
Ok! Thank you for the quick response!
This comment has been hidden.
When I run my C++ solution I get this: Exit Code: 132 Can someone explain what it means and how to fix it?
OP solved the kata; issue not reproducible with his code.
This comment has been hidden.
This comment has been hidden.
expected [ 9, 9, 1, 2, 1, 1, 3, 1, 9, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0 ] to deeply equal [ 9, 9, 1, 2, 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] this is run perfect in visual studio code what is the problem here!!!!!!!!!!!!!!!!!
No, your code is wrong. It skips values because you mutate the array while looping through it.
This comment has been hidden.
The test case isn't not helpful. Please add empty arrays and empty objects in your own program.
what 'empty object' ? which language ?
This comment has been hidden.
Did anyone else not recieve any points for completing this Kata? I did not check solution.
Not a kata issue. Wait to see if your stats update later and open an issue here: https://github.com/codewars/codewars.com/issues if not.
This comment has been hidden.
That's because you mutate the list you're iterating through, note the amount of 0s that your code skipped and how many pairs of 0s you have in the input.
This comment has been hidden.
Ranks can't be changed.
The only reason I agree it being a 5kyu is the test cases being bad. Thats the only reason it's difficult to me.
This comment has been hidden.
Try formatting your code properly and see what could be missing in it.
Your problem is not a kata issue. Your code is not syntactically correct. You probably copied it incorrectly from your VS.
Thank You so much! I just foget final curly braces!
i tried to get the index of the list but i am getting like this
0 1 2 0 2 0 2 7 2 0
Anyone else have the issue of tests failing but when running the test in VS code it passes?
Read this: https://docs.codewars.com/training/troubleshooting/#works-but-no
Thanks! I'll see if there is something that connects with my issue. It's weird because when I just run the test it transforms the array but doesn't when I run the attempt tests. And when I use the failing arguments in VS code it passes. 🤷♂️
Anyhow, it's likely my issue because I'm in no way as stubborn as a computer
Normally, you shouldn't mutate the array you're looping through, you'll skip values like that. And both your if conditions are the same.
This comment has been hidden.
You should show test data, so I can see myself where is the error. On my data everything is working. The message below doesnt told me anything, I can't see your array. Is it that hard to add 1 line of random test data that can't pass through my function? How can I fix it then?
You can see the tested array:
But I agree that feedback of tests could be improved.
This comment has been hidden.
That's because your code mutates the input.
Thank you for your reply. I already tried to simply return a new array, in this case "temp", instead of rewriting the input. The problem with that, though, is that during testing it won't recognise the new array I'm trying to return and just goes back to the input, thus resulting in an error. Whereas temporarly storing the data in a new array and then rewriting the input seemed to solve the problem.
think about what happens if the arrays ends with one or more zeroes ?
also, please do not open
Issues
so lightly in the futurenot sure why the second test is throwing errors, my code passes the other tests.
How could we know?
After testing your code, please: your code doesn't throw an error, the tests you your answer is incorrect, they gave you your result, and the expected answer. Isn't it enough to have an idea of what's going wrong with your code? Aren't you the one supposed to fix your own code? Your code fails on several attempt tests too.
See there: https://docs.codewars.com/training/troubleshooting/
Being new to programming I've kind of stood away from katas that are 6kyu and below. Is this the easiest 5kyu on this site? lol.
Ranks of katas are not perfect science, they are shared across languages and the difficulty can vary a lot from one to another. Moreover the criterias evolved with times, old katas tend to be easier. Currently it is not possible to change it, so it's better not to pay too much attention to it.
I see! Thank you for the reply.
loved this kata
This comment has been hidden.
Please use the spoiler flag when you post code somewhere, I've just put the flag on for you.
I get this error on Python; NameError: name 'Test' is not defined. Did you mean: 'test'?
Backup your code, click Reset, paste it and try again.
thank you. Worked just fine
Cool task! I don't know how others have it all counted for me
I tried this for python. Code worked fine in jupyter but here saying incorrect
Your code is wrong, not a kata issue.
Read this: https://docs.codewars.com/training/troubleshooting
D translation
The solution of others will always remind my identity as a baby in coding (>﹏<). But this kata gives me a chance to derive a variation of insertion sort, so I will give 8 / 10 for this kata. XD
This comment has been hidden.
Slightly easy for a 5 kyu. I'd have given it a seven, personally.
Changing ranks is expensive, not worth it, and not going to happen. It's not useful to complain about that, just enjoy the cheap points.
SUGGESTION IN DESCRIPTION
Rust translation
approved by someone
This comment has been hidden.
Fixed
Ruby translation
This comment has been hidden.
This comment has been hidden.
In Python, an array (generic programming term) is implicitly a
list
(probably the most common data structure), not anumpy.array
, which is a very specific data structure.There are no data structures named arrays in Python, the descriptions are generic and don't give all the possible details for the tens of available languages.
thas is not true. the datatypes array and list are different: https://docs.python.org/3/library/array.html
I've just learnt Python has arrays since 3.10 (so very recently). Well, I don't know what to tell, I have never seen yet a kata expecting arrays outputs... Probably we should rely on a framework update that would handle this properly. Until now, you would better return lists...
Still, vrx was refering to numpy.arrays.
I am new to katas but not new to python. And I spent a long time banging my head on the error I was getting, cos it was not very helpfull and I was doing what the instruction told me to. So changing the description to list of numbers instead of array might work, or at least making a note to python users.
Sorry for your head, but really I don't think it's going to happen on the hundreds, maybe thousands of katas refering to arrays. I've never seen a kata expecting an array, I didn't even know it existed, and I've never seen anyone complaining about that.
There is allways a first time. The reason there haven't been complains about this is perhaps that this is a basic level test. And a python beginer might not know the difference between a list and an array. But the concept of array (if not the class) exists since python 2.7: https://docs.python.org/2.7/library/array.html
Yeah, arrays in Python have been around for ages. The issue of python authors mislabelling lists as arrays has probably been around just as long. For newer kata, this should come up during the beta process/translation review, but it exists in a lot of older ones.
As for descriptions, array should just be read as a general "sequence" data type, since making descriptions very language specific is quite a hassel.
However in my opinion, the initial solution in Python should definitely refer to elements as lists, not arrays. Reading "array" in the description, but then seeing the argument named "lst" in the initial solution reassures that the input is indeed a list. However seeing the argument named "array" is more confusing, and also misleading to newer users.
Fork updating initial solution
@vrx- if you encounter other python kata which wrongly refer to arrays in the initial solution, feel free to solve and then fork and update the python translation (as I have done here). Once you've published the fork, you can post it in the kata discourse for someone to review.
@Kacarott, thank you for acknowledging this. I would probably have realized that it requests a list if I had looked closer to the expected output or the tests, but I usually don't look at tests unless I get a failing test, and the result I got was not a failed test but an error in the code (That was what was frustrating because the code had no errors). And because I am an instruction follower, I can easily dismiss a missing parenthesis in the ([]) sequence. Your solution looks clever to me. Thanks.
I feel the question should have specified inplace shifting the zeros at the end in a single loop, it would have made it slightly more challenging.
This comment has been hidden.
you are not supposed to explicitly call the function on your own
remove the last line
console.log(moveZeros([1,2,0,1,0,1,0,3,0,1]))
console.log is present for debug purposes here. It doest affect return value and testing works fine at codewars when console.log is present. I have already found out that my issue was caused by different behaviour of sort in node versions. It has been changed since v11.
Rust translation
Very easy kyu.It should be 6 kyu
totally agree
bruh serious over-ranking issue..
akar-0 my rank is not increasing what to do?
i am not getting promoted from 5kyu to 4kyu
Sometimes there is a lag for the actualization of profiles.
This comment has been hidden.
Don't post solutions in Discourse. Not a kata suggestion (= suggestion of improvement of the kata).
that was an accident sryy
I can see how this would be easy if you thought of a certain way of doing it off the bat, but as someone who did not, it was quite frustrating lol. Good challenge though
Golang tests are not ok, please solve it
Sample: original [1 2 0 1 0 1 0 3 0 1] Expected solution [1, 2, 1, 1, 3, 1, 1, 1, 1, 0, 0, 0, 0] REal solution [1, 2, 1, 1, 3, 1, 0, 0, 0, 0]
If the error message is like this:
The first one is what your function returned and the other the expected value.
I'm doing this with PHP. Everything fell into places except that my null and boolean values are considered zeroes. Probably a datatype error from my side. Any reference from where I can learn to solve this?
This must be the easiest 5kyu. Atleast, in C++. :-)
This comment has been hidden.
That's a problem with your code, not a kata issue:
This comment has been hidden.
Guide on how to post your code here: https://docs.codewars.com/training/troubleshooting/#post-discourse
About your problem, you're mutating the list you're iterating through, you can see that here: https://pythontutor.com/visualize.html#mode=edit
This was very helpful. Thanks for taking the time to reply. Much appreciated.
This one was weird :D I spent like 1 min to complete it, and after seeing the end solutions I got a bit surprised, why all of them were so complex :\
This comment has been hidden.
The tests are fine and your code is wrong, it fails with inputs like this:
[1, 0, 0, 1]
. Please read this: https://docs.codewars.com/training/troubleshootingI'm not sure if I wrote new Best Practices, but if I did, I would appreciate if you voted up the solution, so others can see it.
https://www.codewars.com/kata/reviews/52597aa56021e91c93000cb3/groups/62496945be5665000101ca94
I don't know if you wrote a good practice code, but I'm sure of one thing: posting a link to your solution requesting upvotes is unwelcome. Think that more than 80,000 people solved this kata...
That's the reason for requesting upvotes rather than just waiting: new solutions have little chances to be seen no matter their quality.
This is simply a fact of life. The early bird gets the worm. The only way around this is to "get better". Because a) you'll start to realise how meaningless upvotes really are and b) the more difficult the kata, the more experience users who solve it actually have and thus are better qualified to judge truly good code, which makes upvotes almost meaningful.
I think it's too easy for level 5
Ranks of approved katas won't be changed.
This comment has been hidden.
I'm stuck (at the JavaScript version) and am not sure what's the matter. Getting everytime errors in the random test cases, for example:
My console output says the content of my result variable is
[ null, '4', 1, 9, true, null, 9, [], '7', '8', [], null, '4', 1, 3, '0', 0 ]
which is the right answer if i understood the task correctly. So does the test possibly have a wrong expectation?'0'
is not0
.My solution preserves the type (in my result variable you see both:
..., '0', 0 ]
). The assertion is tested against a wrong value (you see a'0'
on 3rd place) - and that's definetly not my resulting array, already checked that.Or maybe the task instructions are not specific enough to say: sort only the integer zeros to the end but retain the string zeros? But I think I had one case before that expected to sort the
'0'
to the end, too..Check better. Tests are fine. This can help: https://docs.codewars.com/training/troubleshooting/
Not a kata issue (=bug). 40,981 completions in Javascript (!).
:\
I am also solving this kata with the help of JS. I don't understand it totally!
i shouldn't have to deal witht this shit... seriously... all I do is copy-paste from Kata's "example arrays" and suddenly my array is a string. it's been 2 hours, i deleted my code 6 times, just because of this, it's not fair.... it's just not... if i were stupid and the code would be my fault, i would understand, but having EVERYTHING break because I copy-pasted the sample arrays is just not fair to my time and energy.
What? It's completely fair. The example tests have the correct data. How you manage it it your business. And by the way, please mind your language.
Can someone please explain to me how the heck is this a string? x = [1, 2, 0, 1, 0, 1, 0, 3, 0, 1]
The one below, is NOT a string, but the one above is a string, How is that even possible? x = [9, 9, 1, 9, 9, 9, 9, 9, 9, 9, 7, 4, 0, 0]
Python, you're drunk...
This comment has been hidden.
Your code returns bad answers, this is not a kata issue. Please read the doc: https://docs.codewars.com/training/troubleshooting/
expected '["a","b",null,"c","d",1,1,3,1,9,{},9,0,0,0,0,0,0,0,0,0,0,0,0]' to equal '["a","b",null,"c","d",1,false,1,3,[],1,9,{},9,0,0,0,0,0,0,0,0,0,0]'. Execuse me, but where the hell false and empty array in expected result comes from? If to look at this accurately, it is false among 1 and 1 after "c" and "d" appeared and empty array between 3 and 1 latter. I guess the test machine is totally broken or exactly this kata's test contains bugs. I suggested 3 approaches and my last one shows me expected some pretender values in the result...
They come from the original input array which your solution is processing incorrectly. All the tests are correct, not an issue.
Alright, found the bug in data types. Thx!
I'm getting the same issue in PHP. What's the solution for the missing datatypes?
There is something wrong with this testing:
moveZeros([1,2,0,1,0,1,0,3,0,1])
expected '[1,3,1,1,2,1,0,0,0,0]' to equal '[1,2,1,1,3,1,0,0,0,0]'
Your answer is wrong.
There is something wrong with this testing clause: a,0,0,b,,c,d,0,1,false,0,1,0,3,,0,1,9,0,0,[object Object],0,0,9
there should be a , in the [object Object]? yet i get this error.. wth?
expected '["a","b",null,"c","d",1,1,3,1,9,{},9,0,0,0,0,0,0,0,0,0,0,0,0]' to equal '["a","b",null,"c","d",1,false,1,3,[],1,9,{},9,0,0,0,0,0,0,0,0,0,0]'
The problem is in how you're printing the input, the test is fine.
This comment has been hidden.
if u use del array[i] no doubt it will delete the indexed value ,this causes the array values to shift left by 1 i.e to fill the empty slot but the indexed value from the enumerate function wont update for the modified array , this may lead to skipping of indexes so i'd suggest another approach, even i had a similar approach as yours but then i realised
This comment has been hidden.
Sort wasn't stable until recent Node's versions, so, either you find a way to make your sort stable or wait for this kata to have newer versions enabled.
You can visualize how it behaves with an older version here: https://pythontutor.com/javascript.html#mode=edit
I don't see how i can change code to make it work, so i guess i'll just drop this challenge and move on. Thanks for answer
No problem, you could try not using sort at all.
I dont know why I'm getting an error, actually, a timeout or whatever error, it's not even checking...I tried it on another compiler and it totally worked...it's not working here though!
Did you use 'return' in the code?
great kata! easy if you just want to solve it but cool if you want to practise a better way of solving a problem
This comment has been hidden.
Prove that they need fixing first. Not an issue.
hello brother, i get an error, everything is OK in the browser, please help <3
expected '[9,9,1,2,1,1,3,1,9,0,0,0,9,0,0,0,0,0,0,0]' to equal '[9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]'
Hi. I don't see how we could help you. Obviously your code doesn't do the task properly. What's your question? Have a look there: https://docs.codewars.com/training/troubleshooting/
Brother, the point is that my code works fine if I run it in a browser and it gives the correct result, can anyone help with the code and point out what I'm doing wrong?
No one can help you without your code. Read that link about how to post it using markdown formatting.
I run my function in jsfiddle and chrome console and get result - [9, 9, 1, 2, 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]. But test shows different result - [9,9,9,9,1,2,1,1,3,1,0,0,0,0,0,0,0,0,0,0]. WTF?
Different Node versions probably, make sure your sorting is well defined.
If your code is the one you posted yesterday, your sort is not well defined, read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort It may work in newer Node's versions, but not here if not well defined.
This comment has been hidden.
I changed my solution and I used the documentation on this link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort for the new solution.
Check what your code does here: https://pythontutor.com/javascript.html#mode=edit
Sort wasn't stable until recent Node´s versions, so, either you find a way to make your sort stable or wait for this kata to have newer versions enabled.
Thanks a lot! Interestingly, in a real project, it can be that sorting works so unpredictably?
its not unpredictable, its exactly predictable w.r.t. the fact that all elements which compare smaller end up before any other element which compares greater.
This comment has been hidden.
Instructions: Write an algorithm that takes an array and moves ALL OF THE ZEROS to the END, PRESERVING the order of the other ELEMENTS. Log arr: [ 9, 0, 0, 9, 1, 2, 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9 ]
expected '[9,9,9,9,1,2,1,1,3,1,0,0,0,0,0,0,0,0,0,0]' to equal '[9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]'
Where in the instructions it says that 9 needs to be moved to the beginning, fix it
Fix your code.
This comment has been hidden.
Nothing is correct with this logic. You're providing only partial implementation of sort function. It may work in later node versions, but you can't rely on that.
This comment has been hidden.
There are 4 nines in both arrays...
Look on the top of the page: this kata has been solved about 80,000 times. Please don't raise issues lightly.
This comment has been hidden.
They don't appear from nowhere, they're are in the input, print it: https://docs.codewars.com/training/troubleshooting#print-input
This comment has been hidden.
Please don't give snippet or codes or method to solve a kata without using a spoiler flag, though it doesn't work. Users are supposed to solve the katas by themselves. I don't know what you do exactly but it's always delicate to modify an array while iterating on it. This kata is really easy for a 5 kyu (a fair rank would be 7 kyu), you should try and think by yourself. It's a good idea to print stuff to see what your function is doing in action. This can help: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
It's not a matter of order. You should examine it better.
I think this Kata should be a 6-7 kyu
max 8
Way too easy for a 5 kyu
not a coding guru or anyone great for that matter, but i feel like this should be level 7...
Kyus of approved katas cannot be changed, so it's not useful to post such messages.
Agreed
This comment has been hidden.
Kyus of approved katas cannot be changed, so it's not useful to post such messages.
COBOL translation.
approved
I can't get this one... In c++ I pass simple tests but random test it skips one 0,and i don't know why. Been looking at it for 2hours and cant find the solution. I do a loop trough vector and if it find a 0 it erases it and moves it to the end, but skips one 0 in random. Can someone help pls?
Try:
This comment has been hidden.
Hi, im having the same issue. I don't understand why it's just one random 0 that doesn't work. Any help please? thanks
I wrote my solve with used methods of string without loops. Have solutions any limitations? Samples tests is rigth, but then: RangeError: Invalid count value. So litlle additional tests, difficult to investigate.
Print the input: https://docs.codewars.com/training/troubleshooting/#print-input
This comment has been hidden.
Yes, it's that test, and no, there's no problem with Attempt, remember that sort behaviour depends on Node's version.
what do you mean? which input?
Edited my previous post.
if it this test, then expected array is wrong Test.assertEquals( JSON.stringify(moveZeros([9,0.0,0,9,1,2,0,1,0,1,0.0,3,0,1,9,0,0,0,0,9])), JSON.stringify([9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]) );
Wrong why?
In the error message:
my func returned '[9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]' check
Not here, with Node 10, no. That's why you see the error message.
understood, thank you friend
This comment has been hidden.
No, this is the expected output for that input:
["a","b",null,"c","d",1,false,1,3,[],1,9,{},9,0,0,0,0,0,0,0,0,0,0]
. In the values you posted, where did[]
andfalse
go?oh i was checking the wrong output. Thanks for the help.
expected '[9,1,2,1,1,3,1,9,9,9,0,0,0,0,0,0,0,0,0,0]' to equal '[9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]'
Incorrect test. Fix it
The test is correct, not an issue.
The tests are fine, print the input see why your code fails, fix it.
you're right, it's my mistake, thank you
I would not say that this is a 5-kyu - maybe 6 at max
Ranks can't be changed ATM
Expected: Array ( 0 => 9 1 => 9 2 => 1 3 => 2 4 => 1 5 => 1 6 => 3 7 => 1 8 => 9 9 => 9 10 => 0 11 => 0 12 => 0 13 => 0 14 => 0 15 => 0 16 => 0 17 => 0 18 => 0 19 => 0 ) Actual : Array ( 0 => 9 1 => 0.0 2 => 9 3 => 1 4 => 2 5 => 1 6 => 1 7 => 0.0 8 => 3 9 => 1 10 => 9 11 => 9 12 => 0 13 => 0 14 => 0 15 => 0 16 => 0 17 => 0 18 => 0 19 => 0 )
The the above is my failed test...I am having trouble distinguishing 0 from 0.0 in my code using php. Cannot seem to figure this out. Any advice?
the same situation. And my local php 8.0 server gives correct result: array(20) { [0]=> int(9) [1]=> int(9) [2]=> int(1) [3]=> int(2) [4]=> int(1) [5]=> int(1) [6]=> int(3) [7]=> int(1) [8]=> int(9) [9]=> int(9) [10]=> int(0) [11]=> int(0) [12]=> int(0) [13]=> int(0) [14]=> int(0) [15]=> int(0) [16]=> int(0) [17]=> int(0) [18]=> int(0) [19]=> int(0) }
Pretty simple for 5 kyu :D
The parameters are incorrect for the initial test. The directions explicitly state that all inputs are arrays. However, the second test input is a string moveZeros( "1,2,1,1,3,10,0,0,0" ) expected to return[1,2,1,1,3,1,0,0,0,0]
Hi,
This input doesn't exist as a string anywhere in JS tests. I guess you're using something that had misled you when you printed the input array.
Note: next time, don't forget to mention the language.
Closing & cheers
This comment has been hidden.
this one is actually not suitable to label as 5kyu, please put its rank down a bit
Ranks of approved katas cannot be changed.
expected '[0,9,9,9,1,2,1,1,3,1,9,0,0,0,0,0,0,0,0,0]' to equal '[9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]'
That is wrong! Fix your Kata!
What exactly is wrong with the kata?
From what you pasted, your solution has one zero in the beginning. It looks like an error in your solution.
Your code is wrong! Nothing to fix! Not a kata issue!
A zero in first position is clearly wrong. Refer to this article for more tips: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
expected '[1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]' to equal '["a","b","c","d",1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]' Where do these letters come from?
From the input list, the first value in the error message is what your function returned, not the input, if you want to see it, print it.
this one is realy easy, should be 7 or 8 kyu
I find 5kyu overrated as well. It was fun anyway.
Ranks won't be changed on approved katas. So it's useless complaining about it.
Hi! I've solved this problem in python and i get the correct output in vscode but not here for some reason. Could someone help me?
We're not in your head, so not really...
Maybe this article can help you: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
I figured it out.Thanks!
Hey dude can you share what you did. I'm facing the same problem
This comment has been hidden.
Please don't post code in discourse. The solution page is here for that. If you have a question, then mark it as a question and ask a question.
Thank you, will take care in future.
This comment has been hidden.
Hi, I don't understand the error here, after coding and passing the first test, the attemp before submitting is failing with the following error
expected '["a","b",null,"c","d",1,1,3,1,9,{},9,0,0,0,0,0,0,0,0,0,0,0,0]' to equal '["a","b",null,"c","d",1,false,1,3,[],1,9,{},9,0,0,0,0,0,0,0,0,0,0]'
is there an issue with the tests? or am i misunderstanding something? shouldn't be equal to the following --> [a','b',null,'c','d',1,1,3,1,9,{},9,0,0,0,0,0,0,0,0,0,0,0,0] This is what my code is returning.
No, print the input.
I printed the input here, I added "After Filtering Array" to console.log.
After Filtering Array [ 1, 2, 1, 1, 3, 1, 0, 0, 0, 0 ]
After Filtering Array [ 9, 9, 1, 2, 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
After Filtering Array [ 'a', 'b', 'c', 'd', 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
After Filtering Array [ 'a', 'b', null, 'c', 'd', 1, 1, 3, 1, 9, {}, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
expected '["a","b",null,"c","d",1,1,3,1,9,{},9,0,0,0,0,0,0,0,0,0,0,0,0]' to equal '["a","b",null,"c","d",1,false,1,3,[],1,9,{},9,0,0,0,0,0,0,0,0,0,0]'
I'm not getting why this is failing.
That's not the input, that's the array after you've manipulated it. Print the input as your function receives it, before doing anything to it.
Same problem, in my IDE, that work but on codewars, same error.
Hello! I dont understand. why if "moves all of the zeros to the end", give me an error: expected '[9,0,9,1,2,1,1,3,1,9,0,0,9,0,0,0,0,0,0,0]' to equal '[9,9,1,2,1,1,3,1,9,9,0,0,0,0,0,0,0,0,0,0]'. Nothing to say about 2 zeros one by one in [ 9, 0, 0, 9, 1, 2, 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9 ]. Why i should ignore second zero.
The first value is what your function returns, you shouldn't ignore any zeros.