6 kyu

Tree Depth

463 of 527leesharma
Description
Loading description...
Trees
Recursion
Fundamentals
  • Please sign in or sign up to leave a comment.
  • juliangalardi Avatar

    This comment has been hidden.

  • gabrielkunkel Avatar

    This comment has been hidden.

    • FArekkusu Avatar

      I think the JavaScript tests should be tweaked. There's a few questions about it. Coders have to mess with it in order to get it to pass.

      What's wrong? How should it be tweaked? Why? All tests are correct, and expect you to modify the input object.

      Issue marked resolved by FArekkusu 6 years ago
    • gabrielkunkel Avatar

      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.

    • FArekkusu Avatar

      I've just checked the description and this particular test indeed contradicted it. Reset the trainer and try your code again.

    • gabrielkunkel Avatar

      Passes that test now. Cool. Thanks so much.

  • Jomopipi Avatar

    [JS]

    for test "handles deeply nested objects" my output is

    {"a1":1,"a2":2,"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"depth":11},"depth":10},"depth":9},"depth":8},"depth":7},"depth":6},"depth":5},"depth":4},"depth":3},"depth":2},"depth":1},"depth":0}
    

    but I got

    Wrong deepest depth - Expected: 11, instead got: undefined

    why?

  • bhu Avatar

    the 'typeof' output for [] is 'object' in ES6 which seems to make things hard...

  • mjstromberg Avatar

    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.

  • Blind4Basics Avatar

    @cliffstamp:

    and AGAIN, you messed the things up...

    ruby: random tests send the expected output to the user: see this fork

    • cliffstamp Avatar

      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.

    • Blind4Basics Avatar

      I don't see any modification to the tests. did you update them or not?

  • FArekkusu Avatar

    No random tests in JavaScript.

  • Voile Avatar

    Needs random tests

    • cliffstamp Avatar

      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.

      Issue marked resolved by cliffstamp 7 years ago
    • FArekkusu Avatar

      Could you not close the issues before they are resolved, ffs?

  • animatedgif Avatar

    IMO it's very important to assert that the method does NOT modify the original Hash.

    • Kache Avatar

      Maybe the problem was changed, but this wasn't a problem for me.

    • Voile Avatar

      If the Hash is modified in place the method name should end with a !, according to convention.

    • JohanWiltink Avatar

      .. takes a .. hash .. and returns that hash ..

      ( 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?

    • cliffstamp Avatar

      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?

      Issue marked resolved by cliffstamp 7 years ago
  • Abbe Avatar

    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.

    • JohanWiltink Avatar

      Depends on what you consider the JS equivalent of a Ruby hash.

      The way it's written, an Array is not, but a Date or a RegExp 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 a Boolean, String or Number ( /= 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 ).

    • Abbe Avatar

      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 an Object.

      I'll change it now and edit the description.

      Thanks for going through old stuff! :-)

    • Abbe Avatar

      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.