Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
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)
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.
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
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.
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.
Lol...you weren't that overzealous. Seems pretty modular but still totally reasonable.
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
isundefined
.Is it possible to test what is sent to standard out?
+1 for YOLO
Looks like most of us arrived at basically the same thing!
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]])
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()
orgetNumber()
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.I like how you created a contains(x) function.
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
andArray.reduceRight
as well.Loading more items...