Ad
  • Custom 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

    @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

    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

  • Custom User Avatar

    I thought it was as unambiguous. Clearly from the example I ask for elements [0] and [1] to be swapped.

    swap = ary => {
      tmp = ary[0]
      ary[0] = ary[1]
      ary[1] = tmp
    }
    

    Meanwhile, satisfaction suddenly plummets to 83% for no good reason. Sigh :-(

  • Custom User Avatar

    @strangefrond,

    Write a swap function to swap 2 integers in place

    If that is not enough, can you make a "Suggestion"?

    Sorry, I don't understand your second sentence, but this is not an issue. Can you make a "Suggestion" with examples?