6 kyu
Length of missing array
2,170 of 16,922user5036852
Loading description...
Arrays
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.
Considering just how many people missed part of the description, I suggest adding a fixed test case to the sample to account for it. That would likely reduce the amount of comments complaining about random tests being "bugged".
Created a fork that 1) organizes and adds tests 2) updates description for clarity
Honestly, a fun kata, but.. a kata should be made so that we guess the solution, not the description. I spent more time guessing the description than I spent for coming up with a solution. The details/description should be re-written.
Rewritten how? What do you think is missing or not clear?
omg the edge cases almost made me give up :sob::pray:
(PHP) My solution passes the test. But when i click submit it fails the same basic test. How is that possible?
Scala translation
Wrong for [[2, 4], [], [4, 2, 0], [3, 4, 2, 3]]: expected 1 to equal +0
0,2,3,4 should return 0 instead of 1 ? wtf..
Read the description again:
the task is good, but the task is described in an asshole, and the tests do not show what the problem is
This comment has been hidden.
Random tests are fine, not a kata issue.
Chai + assert for CoffeeScript
Python random tests are broken:
Present lengths are
[0, 1, 2, 4, 5, 6]
, so answer should be 3, but it is expecting 0.Never mind I'm wrong, the specs are just really stupid.
python new test framework is required. updated in this fork
Approved
This comment has been hidden.
Fixed in OP's fork
Actual and expected are flipped in PHP
Fixed.
hello! i don't understand what Should pass edge cases means cheers!
Loved it!
This comment has been hidden.
I am having the same issue
EDIT: never mind, solved it, turns out I was reading for length before checking if the array is null or not. thanks to @Chrono79
how to solve this problem: TypeError: Cannot read properties of null (reading 'length'). when function called without argument we get this error(as i know), so how i can solve it for test...?
Make sure the var is something that has indeed a length property before trying to read it.
The way the tests are written for this kata make it hard to debug.
For those who have 'length of null' error - one of the test cases includes null value instead of subarray. For better understanding:
[[1], [2, 4], [5, 6, 7], null, [6, 7, 8, 9]].
I've been suffering with this problem for an hour or so,this specific test in this kata just suck!
Read the description better next time, it'll save your time.
Thank you! Spend hour too)))
Function name in Ruby should be
snake_case
How do you know what is the size of original array?
This comment has been hidden.
This comment has been hidden.
I am not going crazy but my array is empty and I am getting the error that TypeError: Cannot read property 'length' of null at getLengthOfMissingArray (test.js:4:9
my code is : [].length == 0 return 0
but instead I am getting the error.
null
is not the same as an empty array. You can't read the length of null and that's what the error is about.You have a typo in your code:
It's
length
, notlenth
. But fixing that would break your code.I didn't change my code and it worked :) I have a guard around null check but problem was around empty array, something like this [] and it was preventing me to call the property [].length Thanks for your message! All worked well
main test passes without errors.
send attemp : value passed - always different 28 or 32 or 36
Time: 835ms Passed: 33Failed: 10 Errors: 1Exit Code: 10
TypeError: Cannot read property 'length' of null at getLengthOfMissingArray (test.js:4:9) at Context. (test.js:38:24) at processImmediate (internal/timers.js:464:21)
"getLengthOfMissingArray" is the name of function you have to write, so the error message is pointing to code that is written by you.
Somewhere in your code, you are trying to access
.length
on something that isnull
(we can only guess where it comes from, without seeing your code).Make use of
console.log
s to see where this happens.Test cases are poorly written.
Nice kata, but I accidentally pressed skip and didn't get the point, damn...^^
It's like an issue in JS
ReferenceError: Test is not defined
Make sure you select
Node JS 14.0
at the top of the trainer page.cool
This comment has been hidden.
You're trying to read the length of None in some part of your code, look for that.
you should mention one of the testcases have null array !!!
It's already there.
no, one of the test cases is {{null},{null, null, null}} and the answer should return 2 !
An array containing
null
is not a null array.so why it gives me this error "Cannot read the array length because "parameter1" is null" ?
Because that's not the test your code fails, print the input properly. And don't try to read the length of
null
.Thank You, finally after hours fighting with (null) i complete it
Using javascript - Really enjoyed this kata, but it is almost as if the test suite isn't running the code properly. I used the failing random and basic test as a test in VSCode and my solution returned the correct answer. Only seems to concern the [] returns 0 criteria. The CW test suite says the ouput was 4 but VScode test suite says the output is 0... Is it just me?
Your code is wrong, please read this: https://docs.codewars.com/training/troubleshooting
thanks, i'll check it out!
Forgive my ignorance Chrono, but I still think that there is an error, as when I press 'test', it say's passed, however when I press attempt, it says 1 basic tests failed + 1 random test... According to the page you just sent me, 'test' checks the basic tests... so why does it fail a basic test that it already passed?
Basic tests in attempt tests can be more extensive than the ones on sample tests.
Okay, thanks.. sorry i'm still getting my head round all this
Updated the tests to enable Node 14, changed the blocks to make more visible the tests are different.
In the Java version the random test is buged. I get the following message: "Wrong for [[1, 1], [3, 3, 4, 0], [4], []] expected:<0> but was:<3>" It always expects length 0.
Read the description
the last array is empty so you have to return 0
Not a kata issue.
This comment has been hidden.
From description:
What does you solution return for following inputs:
getLengthOfMissingArray(null)
getLengthOfMissingArray([ [ 3 ], null, [ 4, 2, 9 ] ])
This comment has been hidden.
I have passed basic test, but then I had attempted a solution, I rescieved an error:
TypeError: arrayOfArrays is not iterable at getLengthOfMissingArray (test.js:11:23) at Context. (test.js:52:23)
All other test passed.
Maybe someone knows how solve that problem?
Thanks! I have forgotten, that 0 and null not the same :)
[[3, 1, 1], [2, 1, 2, 2], [2, 3], [2, 4, 1, 3, 4], [4, 1, 2, 3, 3, 3], [3, 0, 1, 3, 0, 4, 0], [4, 2, 2, 4, 2, 0, 4, 2, 0], [4, 2, 4, 4, 0, 2, 0, 4], [2, 4, 3, 3, 2, 0, 1, 0, 2, 0, 4]]: expected 1 to equal 10 It misses array length of 1. Why it asks me for 10?? Edit: I understand now that i need to find which length misses between the given lengths...
second solution is best practice in my opinion.
who asked?
JS: Why if there's an empty array, the function should return 0? They're valid arrays and they have lengths
Author's choice? He left CW, so we'll never know.
This comment has been hidden.
Typescript 3.3 or above should be enabled
currently at
4.2
This Kata is not working properly, event if my tests are passing more then 3,4 attempts there is not button to submit my solution. Please investigate. I'm getting this for some reasons even if the tests are passing. Traceback (most recent call last): File "tests.py", line 55, in test.assert_equals(get_length_of_missing_array(test_case), reference(test_case)) File "/workspace/default/solution.py", line 2, in get_length_of_missing_array array_of_arrays.sort(key=len) TypeError: object of type 'NoneType' has no len()
I'm using this solution: def get_length_of_missing_array(array_of_arrays): array_of_arrays.sort(key=len) counter = None print(array_of_arrays) for x in range(len(array_of_arrays)): if len(array_of_arrays[x]) == 0 or len(array_of_arrays) == 0: return 0 if counter != None and counter + 2 == len(array_of_arrays[x]): return len(array_of_arrays[x]) - 1 counter = len(array_of_arrays[x]) return 0
Even if my tests are passing I'm not able to send the solution and the only option is to attempt more than 1 time. Anyone can help me with this?
This comment has been hidden.
Not a kata issue.
LOLLL you're using B1AD's pic as your profile pic?!!! I'll call that a theft but kinda hilarious XDDD
I would not say that the kata is bad, but it annoys me personally that in one kata you need to solve two unrelated problems: the kata itself and a large number of validations. I would split these tasks into two independent kata.
why in my PlayCode sandbox everything works fine with the same code but there it cant pass through tests....
Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
test cases are super annoying. it is much easier to work with when you can see the return values on a one by one test basis.
This comment has been hidden.
Yeah, i passed all tests but was length error, i just checked if arrayOfArrays is null and returned 0 if it is null
This comment has been hidden.
You're mutating the input array, breaking the error message generation, changed the tests to avoid that.
This comment has been hidden.
read the complete error message to see from where the error is raised, then amend your code. ;) (and don't forget to print stuff to the console if needed at some point).
EDIT : and read the message just below...?
This comment has been hidden.
You have to mention, what one of your testcases is simple (null). Not an array with null, not an empty array, nothing. Took me 30 minutes to realize, what was wrong.
I agree with the comment of kfh132003. Need to add in "visible" tests an array of arrays like [[1, 2, 3, 4], [1, 2, 3], [1, 2, 3, 4, 5, 6]] --> 5 because in random test cases such arrays are found. P.S. Kata -> good =)
There is no need to sort the array in order to find the length of the missing one.
why not?
This comment has been hidden.
I think that the value used in the assertEquals in the "Attempt" tests set IS incorrect for some test.
[[40,50,27,7,29,50],[16,10,43,15,27,13,47,46,23],[18],[19,45,4,10,8,10,35,37],[43,48,27],[40,42,29,12],[7,22,28,0,11,0,14],[30,8,31,33,36,38,13,2,12,22],[],[45,1,43,2,25]]
The assertion for this array of arrays is expecting 1 as the result, but the array size that's missing is 2.
I added that same array with the expected '1' to the sample tests. It fails. When I change the expected size to 2, it passes.
My code outputs the size of the passed sub-array sizes. Here are my test cases, and the code output:
class MyTestCases extends TestCase { public function testBasicTests() { $this->assertSame(getLengthOfMissingArray([ [ 1, 2 ], [ 4, 5, 1, 1 ], [ 1 ], [ 5, 6, 7, 8, 9 ]] ), 3); $this->assertSame(getLengthOfMissingArray([ [ 5, 2, 9 ], [ 4, 5, 1, 1 ], [ 1 ], [ 5, 6, 7, 8, 9 ]] ), 2); $this->assertSame(getLengthOfMissingArray([ [ null ], [ null, null, null ] ] ), 2); $this->assertSame(getLengthOfMissingArray([ [ 'a', 'a', 'a' ], [ 'a', 'a' ], [ 'a', 'a', 'a', 'a' ], [ 'a' ], [ 'a', 'a', 'a', 'a', 'a', 'a' ]] ), 5); $this->assertSame(getLengthOfMissingArray([ ]), 0); $this->assertSame(getLengthOfMissingArray([[40,50,27,7,29,50],[16,10,43,15,27,13,47,46,23],[18],[19,45,4,10,8,10,35,37],[43,48,27],[40,42,29,12],[7,22,28,0,11,0,14],[30,8,31,33,36,38,13,2,12,22],[],[45,1,43,2,25]]), 2); } }
MyTestCases testBasicTests -------- Log ---- sizes: 1,2,4,5 Missing: 3 sizes: 1,3,4,5 Missing: 2 sizes: 1,3 Missing: 2 sizes: 1,2,3,4,6 Missing: 5 sizes: 0,1,3,4,5,6,7,8,9,10 Missing: 2
I cannot pass this kata until the source data is correct.
I am getting the same thing, I can pass all the basic tests but it fails when I try to submit
I'm getting the Error Code 139 and I don't even know what this means.
This doesn't only concern this Kata, I've had this issue on many Katas and I don't know where this error comes from.
However the tests look tricky, and as far as I'm concerned my code should work
I really have no clue but I get the results below. I thought if you get all the assertions it's a full pass if someone could explain I would love it. I'm defintely trying to learn.
KataTests Basic Tests (6 of 6 Assertions) Random Tests (40 of 40 Assertions)
Test Passed: Value == 0 (<---Obviously just one of the passed tests but right below it is the error) TypeError: Cannot read property 'length' of null at getLengthOfMissingArray at /home/codewarrior/index.js:45:23 at begin at it at /home/codewarrior/index.js:34:3 at /runner/frameworks/javascript/cw-2.js:152:11 at Promise._execute at Promise._resolveFromExecutor at new Promise at describe at /home/codewarrior/index.js:33:5 at /home/codewarrior/index.js:81:5 at Object.handleError
You're trying to read the length of
null
, that's what the error says. You have to check if it is an array first.This comment has been hidden.
This comment has been hidden.
Hey, the basic test for the empty array of arrays is returning some kinda of javascript error within the codewars js engine. I tested on a couple different versions of JS locally and got no issues. This Kata is currently unpassable with this issue.
No problem with the kata.
Please when you report a problem, paste the error message you see, and when you need help with your code (as it seems to be the case), we need to see it too. Don't forget to mark your post as having spoiler content if you do paste it here.
In JAVA:
Basic test passing. Then I click ATEMPT, Random test is passing but Basic Test is not passing. For the same code... ???
Please help vote up this comment and resolve this issue.
Only because your code is not working, this is no issue!
This comment has been hidden.
Why is the if inside the loop? See the loop condition, it'll never enter in those cases.
Also, if you have a null reference at arrayOfArrays[i], then the condition: if((arrayOfArrays[i].length==0)|| (arrayOfArrays[i]==null)) Will throw a null pointer exception, since it will try to find the length of the array first. Put the null reference check first and it will enter the if statement correctly: if((arrayOfArrays[i]==null) || (arrayOfArrays[i].length==0))
Could you entertain me with an explanation as to why there is no description of the assertions?
While the rules of the problem are valid, the test cases are extremely unclear.
I got error message even the test is passed. I delete all the code, just kept the return 0 if array.empty? and i got error below the right return.
Test Passed: Value == 0 # main.rb:5:in
getLengthOfMissingArray' main.rb:21:in
block (2 levels) in ' /runner/frameworks/ruby/cw-2.rb:180:inwrap_error' /runner/frameworks/ruby/cw-2.rb:72:in
it' /runner/frameworks/ruby/cw-2.rb:206:init' main.rb:10:in
block in ' /runner/frameworks/ruby/cw-2.rb:55:inblock in describe' /runner/frameworks/ruby/cw-2.rb:46:in
measure' /runner/frameworks/ruby/cw-2.rb:51:indescribe' /runner/frameworks/ruby/cw-2.rb:202:in
describe' main.rb:9:in ` 'This comment has been hidden.
Make sure you're catching these cases:
I dunno C++ version but in javascript (and probably other languages) there are tests where the shortest array's length isn't 1. I'm not sure but if the code follows the description there should be only one array missing.
I checked both. Is the arrayOfArrays.empty() and also are the stored array empty -> if so i return 0. Thats why I`m also a bit confused.
C++;
May I made a mistake, but why only the random test can catch them. I also thought about an abs(), but from my point of view the number should never be smaller than zero if i compare the max possible size with the actual size of all arrays.
Arrays can have an offset.
Thx.
This comment has been hidden.
What`s wrong?
BasicTests Runtime Error Occurred java.lang.NullPointerException
This comment has been hidden.
when I use
Arrays.stream(arrayOfArrays)
, I gotwhy?
Arrays
->cannot find symbol
=> Guess what you forgot to put in your code? (it's a classic when you're coding directly on CW instead of your IDE)you need the operator, "import", sir. like this: "import java.util.Arrays;".
I got "TypeError: Cannot read property 'length' of null at getLengthOfMissingArray...." error at basic test. Other than that, I've passed all tests. What may cause the problem? Also, I didn't understand "If the array of arrays is null/nil return 0" part of the instruction. Because in the sample test ([ [ null ], [ null, null, null ] ] returns 2 not 0. Could you give any example for null array of arrays?
You're trying to get length of null (as the error says). Some of the inner arrays is not an array as you suppose, it's null instead. As for the second question:
getLengthOfMissingArray(null)
<- that.Thank you for the response. Happy coding.
This comment has been hidden.
What about there is only one array, for example [[1,2,3]]? I'm confused.
My code working is properly, but RandomTest not passed, i don't know why!!!!
An answer is only as good as the question.
Hello, I am running into the same issue as fesenkod from a year ago and I'm also using Python:
STDERR: Traceback: in in get_length_of_missing_array TypeError: object of type 'NoneType' has no len()
I check (or I think I'm checking) for an empty array and for None. I pass all tests. I'm not sure what to do. Any help would be appreciated. Thanks
This comment has been hidden.
I had the same problem , but note that the arrays can be something like this too : { { 1, 2 } , {2,4,5,6} }.
I have an error with the testing: "Wrong for [[1, 4, 0, 3, 2, 1, 1], [1, 0, 4, 2, 3, 2], [2, 4], [], [1, 4, 1], [0], [3, 4, 0, 4, 2]] expected:<0> but was:<4>" though the missing array length should be 4...
Next time before you create an issue, you should read the description of the kata!
"If the array of arrays is null/nil or empty, the method should return 0.
When an array in the array is null or empty, the method should return 0 too!"
Will do :). Thanks!!
:-)
Have a good time on CodeWars!
My program runs well on g++ but failed the sample test. Does anyone has the same problem?
This comment has been hidden.
I get a random test failure: aka '22 should equal 7'
very confusing error message
The test is bugged! I had to hack my solution to pass it! whenever the shortest array in list of arrays is 0, the test expects 0 to be returned, which is wrong
Sorry, didn't read the full description of the Kata, but it doesn't make much sense to return a zero, when a gap is there... You are right, as it is - it's not an issue, it's a suggestion instead
System.ArgumentNullException : Value cannot be null. Parameter name: source
How can I solve it? I do not have a variable named Source. I'm not good at english, so I'm using Google to translate.
You should check for null first.
From the description: "If the array of arrays is null/nil or empty, the method should return 0."
Thank you for your help:)
This comment has been hidden.
I analyzed RandomTest and I think author should added extra case in simple (visibly) tests or in description of task: What smallest inner (not NULL) array can have size > 1.
Example: [[1, 2, 3, 4], [1, 2, 3], [1, 2, 3, 4, 5, 6]] --> 5
Is there option to see input arrayOfArrays in RandomTest? It is only test that doesn't passes in my case. I know there is source code in "Show Kata Test Cases" but is there easier way?
Thank SteffenVogel_79 !
How do you declare separate functions on this? I'm using C++11 and sort function in the algorithm library. It requires a 3rd argument which must a function returning a bool.
This comment has been hidden.
3 different correct solutions (including the most upvoted, copy and pasted), passed the basic tests but gave a "SIGSEGV" error when submitting. Seems to be a problem with the Kata implementation.
I tried it again and it works without any problems...
Could you post exactly the code, you used? (Mark as spoiler!)
Having a similar issue in csharp. Get a NullReferenceException when the BasicTest should pass.
@iannoyesdev: You should check for null before as it is said in the description!
"If the array of arrays is null/nil or empty, the method should return 0.
When an array in the array is null or empty, the method should return 0 too!"
This comment has been hidden.
This comment has been hidden.
Finally past the kata, just heads up anyone who may need help, this Kata meants:
otherwise according to author's explanation.
Yes, exactly as it is said in the description! :-)
"If the array of arrays is null/nil or empty, the method should return 0.
When an array in the array is null or empty, the method should return 0 too!"
But good to have it in other words. :-)
Why then we have such a codestring in a sample test: "Assert.AreEqual(2, Kata.GetLengthOfMissingArray(new object[][] { new object[] { null }, new object[] { null, null, null } } ));"? Are not we should expect 0 here? I don't get it. Please help. Only problem I got is NullReference exeption in Kata Assertion.
I am getting the same NullReferenceException. I pass the sample tests but get this error when I Attempt. The sample test allows for elements to be null as WildZes mentioned. Otherwise I am almost positive I'm covering the other conditions. Is there a way to see what test values are being used on my code?
Found the problem! :)
Really helped - thank you very much!
kata hint != kata suggestion (Description mentioned these clearly)
Misleading instructions, in a couple of places:
"You get an array of arrays."
One of the test inputs is an empty array, [], another is the value null, and others are arrays that contain the value null in place of one or more arrays. This makes your very first statement incorrect; the first two of these specific examples are not arrays of arrays, and you could easily argue that the thirs example is not either. (Is a mixed array of arrays and numbers an "array of arrays"? I don't think so. Likewise, I do not think a mixed array of arrays and null values is an "array of arrays".) You could dramatically improve the instructions for this kata by modifying this first sentence: "The input to the function may be null, or may be an array. If the input is an array, it may be empty, or may contain null values and/or one or more arrays."
"When an array in the array is null or empty, the method should return 0 too!"
So "when an array...is null", the method should return 0.
An array cannot be null. It can contain null (or even multiple nulls), but it cannot be null. I think many of the questions asked in this thread relate to this misleading clause. You could correct this by modifying the misleading clause:
"When a component array in the array is empty, or when the component is the value null, the method should return 0 too!"
I completely agree. Every time I thought I had solved the exercise it turned out there was another edge case I hadn't accounted for. On top of that the first initial test cases are all arrays of arrays so I thought I had solved this relatively quickly. It's frustrating when the difficulty in a problem is not the problem itself rather stumbling through the poor instructions.
I disagree with both of you. As you can see 1675 people solved this kata. So it seems, that they understood the instructions.
To solve a kata does not mean, to type the description of the kata in a computer language! It is thinking, trying, tranforming and testing. This kata is not so hard to understand.
This comment has been hidden.
You need to check for None
Hi everyone.I have problem in BasicTests.It throws a NullRefference exception,although in visual studio 2015 all the cases of basic tests work properly.Is here abyone who solved that problem?Random tests pass ok.
Sorry for that dumb comment already solved the problem,I just had to check if the arrayOf Arrays is null or not)
No problem. Great, that you found the problem.
i am truly amazed at how many people are complaining of the same problem.... it's almost as if no one reads the descriptions :') :')
This comment has been hidden.
Before you create an issue, you should read the description!
"When an array in the array is null or empty, the method should return 0 too!"
For java the answer is wrong, the answer of the following question should be 2 not 0! Wrong for [[1, 0, 3], [1, 1, 1, 1, 4], [4], [3, 2, 0, 2], []] expected:<0> but was:<2>
From the description: "When an array in the array is null or empty, the method should return 0 too!" So 0 is correct.
I am getting a TypeError (cannont read length of null). I have tried commenting out various parts of my code and still can't track it down. All the tests pass, just can't get rid of the error. Based on the instructions, "when an array in the array is null or empty, the method should return 0 too!" The issue is that in the first batch of tests there is one like this:
Test.assertEquals(getLengthOfMissingArray([ [ null ], [ null, null, null ] ] ), 2);
which has null, and the answer is still '2'.
Any suggestions?
You have to check the whole array for null. And every array in the array. In the shown test only the values are null, which is allowed.
This comment has been hidden.
From the description: "When an array in the array is null or empty, the method should return 0 too!"
You have to check for null.
Thank you for help, I new in coding and sometimes miss simple things.
the random test got problem??
No. Why?
Am I missing something? Wrong for [[], [2], [4, 1, 3, 3, 1], [4, 3, 1, 0], [0, 2, 0]] expected:<0> but was:<2>
From the description: "When an array in the array is null or empty, the method should return 0 too!"
I struggled with this one in Javascript, but mostly because I forget to appreciate how much leeway one is given in JS regards type checking. I learnt to really appreciate what undefined, null and the quirks of empty arrays in this kata.
Great, that you solved it! :thumbsup:
I liked it somewhat, but the large amout of tedious pre-conditions you have to check is annoying. Also, you should probably state more clearly that the length of the arrays can start at something higher than 1, because all the examples and tests do.
The basic and random tests in the full suite for PHP might have an issue. The result's always something similar to this: testBasicTests ✘ Failed asserting that 0 is identical to 1. Completed in 0.23ms testRandoms ✘ Wrong for [[],[39],[37,50,15],[49,36,16,17,14],[16,46,12,22,42,16,28,18],[44,18,15,13],[3,31,19,22,41,39,0],[28,37]] Failed asserting that 0 is identical to 6.
Running the code separately actually returns the correct value - 6 for the random case (and whatever other random value the assertion returns). There must be an issue with how the execution's being done
The tests are right. Your code is wrong!
From the description: "When an array in the array is null or empty, the method should return 0 too!"
As you see in this random test, the first array is empty! So the correct answer would be: 0 and not 6
I stand corrected. I missed that detail. Thanks; very simple fix
Great! Have a good time on codewars!
The solution was a bit triky because the description is not accurate.
Where do you think is a problem with the description?
The tricky part was to understand that size can start from any number and there can be more than one size missing. My problem was because I cannot see the entire suite of tests so sometimes is hard to imagine the failing test. You should simply put some more example in the description or more various example test.
There is nothing a word about, that the sizes starts from 1. This was only in your head. :-)
And it is only one size missing. You can just return one value, so why there should be more missing sizes?
It is normal on codewars that you cannot see all suite tests.
Great, that you solved it! :-)
All public examples start at 1, though.
Congrats to 14k! :-)
Hi steffen, thank you for the answer. I think you're right but my suggestion is only to modify the description or the example tests to clarify more.
This comment has been hidden.
No, the test you're showing is wrong. The missing length is also inside and not outside the given lengths.
This comment has been hidden.
It seems you are not checking the arrayOfArray for null. "Cannot read property 'length' of null"
But on line 5 I am checking for null if(arrayOfArrays[i] === null || arrayOfArrays[i].length === 0){ return 0;
}
You are checking the items of arrayOfArrays for null, but not arrayOfArrays itself for null!
Oh yea thanks:)
You're welcome! :-)
For the random tests in Java it appears to have multiple missing array lengths. e.g. Wrong for [ [2, 2, 1, 3, 4, 1, 2, 1], [4, 3, 4, 3, 1, 0, 4], [2, 0, 1, 0, 0, 1], --missing 5 [0, 3, 1, 2] --missing 3 --missing 2 --missing 1 ] expected: 5 but was 1
It is true that 5 is missing but so is 1,2 and 3. Is it expecting to receive the largest missing array?
Is is not always starting at length 1. Here it is starting at length 4. So 5 is really the only answer. :-)
Thanks, I guess I should have worked that out from the example I gave.
I'm having a problem with random tests in C++. The problem states that there will be always a missing array, but it generated a test with continuous length values:
len = 3 2 8 4 len = 4 5 3 6 7 len = 5 5 0 6 5 4 len = 6 0 3 1 1 8 6 len = 7 9 3 6 1 9 3 5 len = 8 9 0 3 0 7 4 2 8
The test case expects 0 as output.
Yes, you're right. Fixed! :-) Could you please try again?!
Still getting the same error :(
I think now I got the problem. Could you please try again?
Yes, now it works! thank you :)
Great! Thank you for reporting the problem. :-)
This comment has been hidden.
This comment has been hidden.
Why are they failing? Can you post the error message with expected and actual value?
This comment has been hidden.
Andrew, there was a bug in the C++ tests... maybe you could try again now?
Thank you! I just passed the test! Marked the question as resolved already.
Great!
The tests for this Kata do not work.
This kata has been solved 474 times without problems. I don't think, that the tests do not work now?
Maybe you have a problem in your code? Please a little bit more details than "do not work"!
Where is the concrete problem? Maybe post your code here (mark as spoiler!)
The tests work.
:-) All right. Great you solved the kata!
This comment has been hidden.
You are not checking, if one of the arrays is null. So you get an NullPointerException if you try to use ".length" of an array, which is null.
My problem is that on random test i get this error message: Wrong for [[], [4], [1, 4, 4, 3], [4, 0]] expected:<0> but was:<3> However You can easily see that expected number should be 3 as stated, not 0.
You can easily see, that it has to be 0 ... It is in the description of the kata: "When an array in the array is null or empty, return 0 too!" :-)
Wow, that was a dumb post from me. Thanks for the answer, but if I may add something, I think it's just little counterintuitive to return 0 when there is a null array in array.
I saw some other people had this problem with different languages- I have it with JS. All tests pass (0 fail) but because of this error I can't submit. I'm not even using length to check the array, for example :
arrayOfArrays = arrayOfArrays.sort(function(a,b){ if(a =="" || b==""){return 0;}
The Error: TypeError: Cannot read property 'length' of null at getLengthOfMissingArray at begin
Any ideas or Tips?
This comment has been hidden.
I did...Didn't want to paste my code because then it would be marked 'comment hidden'
*Checked in Chrome console - if you check for empty array like this: var a =[]; a==''; //true a =[1]; a==''; //false
Am I misunderstanding something?
Besides that wasn't my problem according to the error I recieved...
The answer to your error was "You should check both for null before." I think you did not check the input array for null. So, when you check arr.length == 0 you get the error, because arr could be null.
Paste your code, mark it as spoiler. It is only visible to warriors, who have solved the kata.
This comment has been hidden.
You should check the arrays in the array for null. :-) If one of the arrays is null, you should return 0. Do this before sorting.
This comment has been hidden.
This comment has been hidden.
Thanks So much!! :)
You're welcome! ;-)
I'm facing the same problem
What exactly is the problem?
This comment has been hidden.
The length does not always starts at 1. It could for example be this: [2,2],[8,8,8,8],[9,9,9,9,9]
Your code would answer 1. But the correct answer would be 3!
lul, thanks)
C++-Translation kumited!
Please check it and approve! Thanks. ;)
Approved! Thanks, dude!
This comment has been hidden.
First of all: Do not create an issue, if you do not know, why you get an exception/error. Issues are for known/proven problems.
The problem in your code is the way you checking for null. Check it line for line. I think you will find the problem. Otherwise ask again and I will show you. :-)
Ah OK thank you! I will try to work it out. It was my first ever comment so didn't know about not raising as an issue. Will know for future!
And dont hesitate to ask, if you have questions. :-)
This comment has been hidden.
the description stated:
When an array in the array is null or empty, return 0 too!
you have to deal with
null
.I ran the code in other platform and it was successed.But when I ran the code in this platform it passed too,it gave an error that length is not a function of null
PHP-translation kumited! https://www.codewars.com/kumite/57cb1c52f8392d92ec00003a?sel=57cb1c52f8392d92ec00003a
Approved! Thanks a lot!
Did you know? At the moment you get 5 points per translation. This will increase over 10 to maximum 15 points per translation. :-) I think 15 points is after 30 or 35 translations...
You can see the count of your approved translations here: https://www.codewars.com/users/candrabeqx/site-events (at the last lines of the list at "Code snippet translation approved")
Translations are really good for the community and for getting points. :-)
thank you very much for the information!
I'll keep translating as much as I can ;)
Nice Kata. Thanks!
Glad you like it! :-)
I am facing issue. Got the result "You have passed all tests! :)" on BasicTests while i clicked RUN TESTS. But on SUBMIT i am getting an System.NullReferenceException on BasicTests while the Random Test got passed.
So you should check for null in your code! It is also in the description. ("If the array of arrays is null/nil or empty, return 0. When an array in the array is null or empty, return 0 too!")
I hope this helps!
Why are giving people bad to this kata? If you have/have had problems with the kata, then create an Question or an Issue. Bad voting means, you hated it! I DO NOT UNDERSTAND THOSE PEOPLE! Really!
To create a kata, even an easier one, is always work and time intensive! So it is like a "F U" for the author, who spends time here for you and the community!!
When I run random tests I got following error:
Random Tests ✔ Test Passed ✔ Test Passed ✔ Test Passed ✘ 0 should equal []
I cannot see where in the instructions written that we should return an empty list. So, it may be considered as issue.
UPD: and when I run random tests several times I also often obtain such error: STDERR: Traceback: in in get_length_of_missing_array TypeError: object of type 'NoneType' has no len()
An empty array should return 0. It is in the description. The message from the used test-framework is not so good.
Yes, it is in the description, but why then when I return 0 the test want me to return an empty array?
Which language? Ruby?
Python
Ok, sounds really like a problem. I asked the warrior, who did the translation for help.
Sorry, that's my bad. Please approve the fixed translation. I had to create a fork as the description of the original kata had been changed. Please approve.
Regards,
suic
@fesenkod: Please try again.
Unfortunately, I get the same result. Issue remains.
Try once again please. There was a problem in publishing the fix before.
I still get: STDERR: Traceback: in in get_length_of_missing_array TypeError: object of type 'NoneType' has no len()
But now there no longer are messages like "✘ 0 should equal []"
Do you check for null/nil/nonetype or empty before?
Put here your solution and mark it as spoiler. The translation should work now.
This comment has been hidden.
Sorry, I don't know how to paste the code with all indentation saved.
This comment has been hidden.
You are only checking for an empty array, but not for null/nil/none.
Thanks all!
Great! You're welcome!
For correct indentation and format you have to use ` . Three times at beginning and three times at ending.
Python Translation kumited! :)
Approved. Thanks a lot!
I've also attempted a Ruby Translation. Please, let me know if it looks alright.
Approved! Thanks a lot!
@suic: There seems to be a problem in the Python-Translation. (See comments above.) Can you check this and fix the problem?
Fixed, see my comment under your. :)
Hat Spaß gemacht! :-)
Sehr schön! :-)
So soll es sein!
Hi, there's some issue with random tests. See the example below.
Regards,
suic
E. g.:
But:
Haven't solved it, but in the description you can read: "When an array in the array is null or empty, return 0 too!" So it's not an issue, 0 is correct;-)...
Ok, I misread that.Thanks
About "return 0 too", i think it would be better to change description to "method should return 0 too", because u can misread it as "sub array should return 0 length".
Good hint. Thanks. I changed it that way.