Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    const isLeapYear = y => y % 16 ==0
    this is also my solution but it fails lets say for the year 4 or 8 !!!
    Yes it need to have test cases for this years too!

  • Custom User Avatar

    Yes, especially confusing considering in the example 'coffee' > 'eecoff' results in 2, but in the tests it expects 4 (going the opposite direction). I honestly feel like the description is asking us to go forward but the tests actually want us to go backward.

  • Custom User Avatar

    I agree, the story is nonsense and should just be replaced with a short problem description like yours: "Given a list ls of positive integers, find the length k sublist with largest sum <= t".

  • Custom User Avatar

    To me, that's actually rotating the first string BACKWARDS, not forward... But other than that, the exercise is nice.. :)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    The problem simply asks for the biggest sum of x ammount of numbers under a certain value. The story makes absolutely no sense, since you wouldn't have ALL the distance options from every city, and hence in reality you couldn't pick random distances (unless you had the option of teletransporting from town to town).

    Really think about it, the story here makes no practical sense..

  • Custom User Avatar
  • Custom User Avatar

    Well - to be fair

    • I solved it correctly, which failed the tests
    • I solved it incorrectly, which passed the tests
    • I worked with the author to get the tests correct, which invalidated my solution
    • I submitted my original solution, which now passed
    • and then I submitted this solution, which originally passed
    • and then I worked with the author some more to get the tests even correcter, which invalidated this solution

    I did it to prove a point. In addition to solving it. (Namely, that randomised tests are A Good Thing™. :)

    When viewed out of context, yes, it looks silly. :]

  • Custom User Avatar

    Absolutely silly.. You've worked it out only to give the answers, instead of actually solving it!! :P

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    To return a function, you simply... return a function!! :)

    For example:

    function MagicFunction(...a) {
      function toBeReturned(...a) {
        do {
          // this code...
        } while (somethingIsTrue);
        return something;
      }
    
      return toBeReturned;    // This is how to return a function..
      return toBeReturned();  // This would be, instead, returning a function invocation..
    }
    
  • Custom User Avatar

    I've written this answer based on another one I saw, to prove that the test is wrong. This solution actually FAILS to verify all Leap Years!!!!

  • Custom User Avatar

    Well, this solution is wrong, yes.. But actually the year 2000 IS a leap year, because it is multiple of 400..

    ;)