Ad
  • Custom User Avatar

    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!

  • Custom User Avatar

    @nikolaninkov I am having this timing issue as well. Did you end up figuring something out?

  • Custom User Avatar

    @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 :]

  • Default User Avatar

    Thanks to:

    • @tachyonlabs for approving
    • @kazk and @JohanWiltink for helping me with the code-validator
  • Default User Avatar
  • Default User Avatar

    Your clock is wrong :-)

  • Custom User Avatar

    without needing a temporary variable

    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 a tmp, and a tmp 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. :]

  • Default User Avatar

    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

  • Custom User Avatar

    Done! Please give up now. I've nearly worn out the re-publish button :-)

    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. :]

  • Default User Avatar

    Great kata! Thanks!
    Fun in the morning! :-)

  • Custom User Avatar

    @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.

  • Custom User Avatar

    @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 or Pair or pointer (pass by reference) and we are forced to use Array. It might be helpful to add to the description that the input is always a pair of integers (always ary.length == 2).

    And second suggestion is to change the function to swap(array, i, j) where array.length >= 2 and 0 <= i,j < array.length which swaps elements at i and j.

    Please correct me if I'm misunderstanding you.

  • Custom User Avatar

    @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"?

  • Custom User Avatar

    One more upvote here to help bring it back up :)... thanks for the Kata!

  • Custom User Avatar

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

  • Loading more items...