6 kyu
Tree Depth
463 of 527leesharma
Loading description...
Trees
Recursion
Fundamentals
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 comment has been hidden.
This comment has been hidden.
What's wrong? How should it be tweaked? Why? All tests are correct, and expect you to modify the input object.
I can't see the tests. When I write the test according to the demands in the instructions, it's correct. There's no indication about how the input object should be modified. I'm left guessing what the issue could be.
I've just checked the description and this particular test indeed contradicted it. Reset the trainer and try your code again.
Passes that test now. Cool. Thanks so much.
[JS]
for test "handles deeply nested objects" my output is
but I got
Wrong deepest depth - Expected: 11, instead got: undefined
why?
fixed by modifying the input object
the 'typeof' output for [] is 'object' in ES6 which seems to make things hard...
Please use the correct method (
Array.isArray
) to test if something is an array ;-)could also use tree.constructor === Object
I had to modify the original JS object to get the tests to pass. I thought that was really bizarre. So bizarre that I couldn't tell why my solution wasn't working properly at first.
@cliffstamp:
and AGAIN, you messed the things up...
ruby: random tests send the expected output to the user: see this fork
Thanks, I thought I had that fixed in the reference solution which was mutating input originally. It should be fixed now as it does a deep / independent clone.
I am going to add a check to Ruby's input mutation in the test suite given Ruby has a bang notation for mutating functions.
I don't see any modification to the tests. did you update them or not?
No random tests in JavaScript.
Needs random tests
I am not sure random tests are necessary for simpler katas given large test suites, and the difficulty of hard coding compared to the actual solution.
In any case they are added.
Could you not close the issues before they are resolved, ffs?
IMO it's very important to assert that the method does NOT modify the original Hash.
Maybe the problem was changed, but this wasn't a problem for me.
If the Hash is modified in place the method name should end with a
!
, according to convention.( my emphasis )
Maybe the function should have a different name ( sounds like a very useful convention BTW! ), but that's not the original issue, and I'm not sure it qualifies as an issue ( it might. I don't know how strict that convention is generally adhered to ).
The description is very clear that the hash should be modified in place.
Should this be closed, or not?
I adjusted the reference solution so that it doesn't modify the existing hash.
It doesn't test for not doing this, but almost no kata does that, though it could be a BP for languages like Ruby which have bang annotation for mutating functions?
I added a JavaScript translation. Please check it out.
I use JavaScript objects as Ruby hashes. But I'm still not sure whether I should treat arrays as non-objects or not.
Depends on what you consider the JS equivalent of a Ruby hash.
The way it's written, an
Array
is not, but aDate
or aRegExp
is. A primitive ( boolean, string, number, null, undefined ) should not be; that's obvious.If you consider an
Object
to be an object, everything but a primitive should be, including aBoolean
,String
orNumber
(/=
boolean, string, number ).The best JS implementation of this idea may not be a faithful adaptation of the original ( and the best implementation including Ruby may not be to return the same object modified ).
True. This translation was 3 years ago. If I had done it today, I would not have made an exception for
Array
since it is anObject
.I'll change it now and edit the description.
Thanks for going through old stuff! :-)
I don't know what's the problem, but I can't save my changes.
I fixed the javascript code to treat arrays as objects and I added some random tests.
Can't save from the editor. Tried both yesterday and today. Will try again in a couple of days.