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 just got it to work. I think the issue is just that there are a bunch of ways of trying to compute this that seem fine if the numbers are reasonable, but are not efficient enough for very large numbers (in the millions). I found several working solutions before arriving at an efficient enough one. Perhaps it would help to have a test in the default array of initial tests that includes some larger numbers. For others working on this: there are 160 tests in the final battery. If you completed 10 in the 12000ms, you are not close to being efficient enough. (I never knew while working on it. Wished I had.) Thanks for the kata, g964!
@nikolaninkov I am having this timing issue as well. Did you end up figuring something out?
@dinglemouse, no problem, I had fun :) I hope that was enough but at the same time I want to see some creative solutions bypassing it :]
Thanks to:
:D
Your clock is wrong :-)
I think under the surface the right hand side of the assignment is a temporary variable.
[ ary[1], ary[0] ] = ary
doesn't work; it has to be a new array. It can be garbage collected immediately, but so can atmp
, and atmp
is smaller than an[ ..ary ]
.There would be myriad possibilities with
Array
mutator methods as well, but we can't use them in this kata. Idea for the next? I expect some creativity there. :]Hi @strangefrond.
The description has been updated :-)
Regarding your suggestion, I think you are missing the point. The ONLY purpose of this Kata was to demonstrate that there are ways to swap 2 variable values without requiring a separate intermediary variable. That's it. End of story. Nobody is saying your suggestion is a bad idea, but enhancing this to be a generic/useful swap function is quite unrelated to the aforementioned intention so I won't be going down that route.
Kind Regards. DM
I'll see your re-publish button and raise you my Submit button. :P
But it's OK, I'll give up. Not going all-out JSFuck. I'm out of ideas otherwise. 'twas fun. :]
Great kata! Thanks!
Fun in the morning! :-)
@strangefrond, I agree with you about satisfaction voting is confusingly labeled :( I either vote "Very" or not vote at all. You can undo the vote by clicking it again, if you want.
@strangefrond, I think I understand you now, thanks for explaining in more detail :)
I think the confusion is caused by JavaScript lacking a data structure like
Tuple
orPair
or pointer (pass by reference) and we are forced to useArray
. It might be helpful to add to the description that the input is always a pair of integers (alwaysary.length == 2
).And second suggestion is to change the function to
swap(array, i, j)
wherearray.length >= 2 and 0 <= i,j < array.length
which swaps elements ati
andj
.Please correct me if I'm misunderstanding you.
@dinglemouse @kazk I did not mean to make an "issue." I felt sure I had marked "suggest an optional improvement." Also, this is my first time commenting on any coding website, so my apologies if I was unclear with what I said. There is not a general rule in place that says "If someone uses a value in an example, then you should use that same value in your code," so regardless of whether the example uses the first two items in the array, somewhere it ought to say which two items are to be swapped in the actual instructions for the kata. Since there is no reason to assume that the first two items are to be swapped, and since there is no additional difficulty in writing code that swaps any two items, my suggestion is to pass the array locations of the items to be swapped via arguments to a function and have the would-be-coder make a function that can swap any two items from any array like so: "function swap(arr,first,second){etc...}". I really am sorry if that seems like a bad idea. For some reason I cannot reply directly to your comments and I don't see a way to eliminate the "issue" I never meant to post. Also -- I voted "somewhat," which I assumed would be counted as a "satisfied" vote since "somewhat satisfied" is a sub-genre of satisfied. So my intention here has NOT been to harm this kata. But I'm not intimately acquainted with how the website calculates satisfaction. Is there really no space between only "somewhat" and "very?" Can a person not be simply "satisfied"?
One more upvote here to help bring it back up :)... thanks for the Kata!
This comment is hidden because it contains spoiler information about the solution
Loading more items...