Ad
  • Custom User Avatar

    @ignovak it is always a best practice to keep the original variable intact when it is passed into a function. When a Kata description makes no mention of whether a variable passed into a function should be left intact, you should always assume that a Kata expects the function to be pure.

  • Custom User Avatar

    @donaldsebleung So if the solution using sort is illegal, you should have mentioned this in details. Otherwise it would be correct to fix the kata so that it accepted any kind of solutions.

  • Custom User Avatar

    I think there are two way:
    1.run your check function first, save answer to a value, then send the array to user function.
    2.create a copy of array,send it to user function.

  • Default User Avatar

    Ah, I see. The random tests failed because the sort method for arrays changes the original array. This means that in the random tests:

    1. Initially, an array whose numbers are not in order (e.g. [3,1,2,4]) is passed into your function. Your function then confirms that the array is not sorted since the original array does not equal the sorted array using sort.
    2. However, here is the problem - As you are using sort to do the comparison, you mutate the original array by sorting it. The sorted array ([1,2,3,4]) is then passed into my solution and my solution confirms that the (mutated) array is sorted.

    Perhaps you may want to implement your own sorting algorithm that does not use sort?

    Hope this helps :)

    Cheers,
    donaldsebleung