• Custom User Avatar

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

  • Custom User Avatar

    Nice! Thanks. You've definitely convinced me about this algorithm, though I absolutely disagree with the idea than any "loop inside a loop" is n^2, unless each of those loops grow proportionately to n. These both do, though.

    In light of this test, I'm thinking the best way is to abandon the strategy entirely and use binary search to get O(nlogn)

  • Custom User Avatar

    Neither loop's size grows proportionately to N unless each element is smaller than the previous, in which case each element in the 2nd loop will fail the max gap test and break, thus running in O(n) time.

  • Custom User Avatar

    JS Perf would disagree. Based on the most demanding type of input sets I've seen it's about O(n). If you can find any sort of input for which it's n^2, please share!

    http://jsperf.com/largest-gap/5

  • Custom User Avatar

    I know what Big-O means. Why do you say it's O(n^2)?

    Can you give any example input that would cause this behavior? I don't think that's possible given the use of critical points and aborting for any gap of equal or lesser size to those already found.

  • Custom User Avatar

    I've been coming to the conclusion that this site is fundamentally broken in that way. Most katas' top-rated "best practice" solutions have horrible runtime efficiencies and bad practices! By bad practices, I'm thinking of ridiculous trinary-fueled code golf, using double equals comparisons in JS, monkey patching built-in classes or prototypes, or in cases like this, just not providing a solution that works on edge cases.

    Codewars is the blind leading the blind.

  • Custom User Avatar

    Lol...you weren't that overzealous. Seems pretty modular but still totally reasonable.

  • Custom User Avatar

    Could anyone here share a working example with Test.callCount(methodName). This is my first time designing a kata and according to the feedback I'm getting, Test.callCount is undefined.

  • Custom User Avatar

    Is it possible to test what is sent to standard out?

  • Custom User Avatar
  • Custom User Avatar

    Looks like most of us arrived at basically the same thing!

  • Custom User Avatar

    It returns a slope of Infinity (i.e., a vertical line) if only the denominator is zero, and a slope of NaN in the case of identical points.

    This solution correctly handles both cases and returns true when all the slopes are infinity and false if only some are, while discarding NaNs. Try this input on lv.D's solution:

    onLine([[1, 2], [1, 4], [1, 7], [1,7], [1,4]])

  • Custom User Avatar

    Yes, Ruby also has closures (read up on blocks) and you can do the same things with them. They look really different, though. Of course, Ruby is a class-based language so you should probably just use private class variables in this situation.

    To be perfectly honest, I find trying to shoe-horn JS into a psuedo-classical form pretty repugnant. There's no reason guess() or getNumber() couldn't be stand-alone functions inside a module instead of mucking around with prototypes. Prototypical inheritance allows for some great things, but emulating classes isn't one of them.

  • Custom User Avatar

    I like how you created a contains(x) function.

  • Custom User Avatar

    Oh, right. I used all of those in the interests of not reinventing the wheel. Maybe it would also make sense to disallow Array.forEach and Array.reduceRight as well.

  • Loading more items...