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.
I have seen this in articles describing the varios types of namespaces. I fail to understand the code. Could you help break the code down for me?
No, not significantly. Unless you can make the asymptotic complexity better than
O(n²)
, it's not going to be significant, it's ging to be a micro-optimisation.what about var j = i + 1, for comparing with itself is not necessary
Seems that this solution can't be used like a common solution, see tests here http://stackoverflow.com/a/34466248/3429127.
That means that you should avoid usage of ">" and "<" in comparator.
Just want to notice that JS native sort method affects on initial array.
If we want that list argument stays the same we need to make a copy of it inside the function (e. g. using slice()).
anyway no fun with broken code =)
I like this. LOL! The solution with the highest "best practices" rating, and people talking about how inefficient it is. Of course, you're all right. It's pretty though, and gets the job done. :)
Have a look at this one for comparison... http://www.codewars.com/kata/reviews/525099441625e506d500044e/groups/55aa3eaaa85fdbbedf0000a0
I saw it in a few different kata's solutions. I had the same question.. Correct one is to use substraction.
Came here to ask the same question.
This returns a boolean, which I would guess complies only with returning the 1 or the 0?
How exactly does this solution work?
Defining functions on prototype is usually a better idea: http://stackoverflow.com/questions/4508313/advantages-of-using-prototype-vs-defining-methods-straight-in-the-constructor
Nope @arichidoru, in fact it's even clearer the way you've put it. []s
Is there any particular reason for adding
sayHello()
viaMyClass.prototype
and not directly in theMyClass = function(phrase){this.phrase = phrase; this.sayHello = function(){return this.phrase}}
?Also I suggest you break the inner loop when you find
j-i > result
, since calculating cycles more would be wasteful.The description didn't say not to overwrite a falsey value. It said not to redefine an existing namespace.
That's a good point. It would still be a O(n^2) algorithm but it would cut out about half the checks.
Loading more items...