5 kyu

foldr

Description
Loading description...
Arrays
Lists
Algorithms
View
AllIssuesQuestions2SuggestionsShow Resolved
  • Please sign in or sign up to leave a comment.
  • ozichukwu Avatar

    Description seems vague.

    If i get it correctly, the task is figuring out how the laziness evaluation works right?

    • JohanWiltink Avatar

      Define Array method foldr, which takes a function and an initial value as arguments, and returns a lazily evaluated fold over its this-argument.

      This is the task. Folding and laziness are explained in previous sections.

      I'd describe the task as figuring out how to implement the required laziness; I've tried to describe how it works. Is that not working for you? What could I do to explain it better? ( Keep in mind I already know how it works, so I may be skipping steps I consider completely trivial or do not even recognise as steps. )

    • ozichukwu Avatar

      Thanks for replying.

      I read the description and read through the test cases but i couldn't figure it out. I'll have another look later. :)

      Question marked resolved by ozichukwu 5 years ago
  • Voile Avatar

    Done.

    I'm not too sure how my solution passed, and I'm very sure it's not intended, but apparently it works. Probably has to do with what's being tested.

    Speaking of which, the type of functions and values used in the tests are vital to how to tackle this, so you probably need to document them thoroughly in the descriptions.

    • JohanWiltink Avatar

      The description specifies exactly what arrays will be tested. The tests are there to be read, showing what functions and values are tested. Is that not thorough enough?

      There are no secrets in this kata. I can't imagine someone passing the example tests and failing the random tests - they're the same.

    • Voile Avatar

      Well, I mean based on how my solution is much simpler than yours that maybe something unintended happened. Or maybe something will trip up in my solution but it's not in the tests yet.

    • JohanWiltink Avatar

      This comment has been hidden.

  • Voile Avatar

    The initial code has two function named foldr. This is confusing.

    Maybe change the inner one to something like _foldr?

    • JohanWiltink Avatar

      And both of them are not even the outer method foldr. It's just the way I do that sometimes.

      I appreciate the feedback, but I'm not of a mind to change the setup code. You're free to change it in your own solution; it's not in any way essential.

      Question marked resolved by JohanWiltink 8 years ago
  • JohanWiltink Avatar

    Your comments are most welcome!

    I could have tested with more functions, .some() and .find() would have been very possible to implement with foldr, but it would have been more of the same really.

    I could have expanded the problem to include .foldr(cons,[]) as .slice(), I had that solved reasonably completely ( boast! ), but it would have meant more description, more testing, even more challenge, and the implementation did not fit in very nicely with the current solution. I left that out.

    This kata is a spin-off of class List, where there is more functional goodness and frustration to be had. That one also has a tweaking foldr, but that foldr has its own problems .. :yum: