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.
@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.
@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.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.
Ah, I see. The random tests failed because the
sort
method for arrays changes the original array. This means that in the random tests:[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 usingsort
.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