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.
Sorry, I wrote this about 7 years ago and at the time,
String.prototype.repeat
wasn't standardized. I've updated the description to better match modern expectations. Hope it helpsThis comment is hidden because it contains spoiler information about the solution
A small performance boost which becomes more apparent with larger arrays. Essentially, every time you do
array.length
, the system has to do a value lookup. "Okay, here's some object. Let me look for that property... Found it, now let me return that value." Where as if you do it withlen = array.length
then it only has to do that lookup once then you have a static value reference. Check out this JSPerf for performance comparisons.I think people haven't been upvoting exclusively because of how unique the problem is. It doesn't emphasize a specific feature and focuses more on actual problem solving skill, which I like. I might bump it down to a 6 and aim to push it out of beta.
How is this O(n^2)? I only see it running through the set, at most, once.
This comment is hidden because it contains spoiler information about the solution
I'm running under the assumption that a temperature is a number i.e. a primitive so whichever one is store in the archive is irrelevant. However, if any sort of object were being stored then it could lead to issues when one or the other is updated.
I think for the sake of this kata, it doesn't matter one way or the other.
This comment is hidden because it contains spoiler information about the solution
I think that both the convenience and power of actual getters/setters is too good to ignore. Browser support is iffy but it seems like everyone is getting up to speed rather quickly. As for the performance hit it doesn't seem to be too bad compared to function calls and will likely get optimized in the future.
Of course, as with everything in the world of JS, if you're doing something super performance critical or will be called a lot, it might be better to stick to other methods.
Interesting but aren't you placing temperature and archive in the global scope?
I think that'd be great. After all, who wants to right the "best" solution for everything, especially if you already know how to do it?
This shouldn't work because a or b could be 0.
Doing the basic one is easy. It's a lot more fun if you try and complicate things as much as possible ;)
You are mistaken. It used to be thrown around (and some people still do) that only one return statement means you only have to worry about one return value so it's easier to read. But in this case, it easily follows "I found the thing I was looking for, I'll go ahead and return now." Throwing in some kind of variable to hold your return value, saving that upon finding it, breaking out of the loop, and finally returning your value works just fine but it obscures the reasoning behind it in my opinion.
Now THAT is smart. Well done.