Skip to main content
added 217 characters in body
Source Link
Steve Bunting
  • 1.1k
  • 1
  • 7
  • 18

Your problem is with the following line:

values = result;

You can not assign every value from one array into another with a simple one-line statementassignment like this. In order to change the array 'haystack', the sorted values needsfrom your result array need to be put back into the values array. I believe the best wayYou would probably need to do this is withuse another for loop.

As an aside, you could also simplify this code, removing the cumulative counting, getting rid of the result array altogether and just assigning the sorted values straight back into values.

Your problem is with the following line:

values = result;

You can not assign every value from one array into another with a one-line statement like this. In order to change the array 'haystack', the sorted values needs to be put back into the values array. I believe the best way to do this is with another for loop.

Your problem is with the following line:

values = result;

You can not assign every value from one array into another with a simple one-line assignment like this. In order to change the array 'haystack', the sorted values from your result array need to be put back into the values array. You would probably need to use another for loop.

As an aside, you could also simplify this code, removing the cumulative counting, getting rid of the result array altogether and just assigning the sorted values straight back into values.

Source Link
Steve Bunting
  • 1.1k
  • 1
  • 7
  • 18

Your problem is with the following line:

values = result;

You can not assign every value from one array into another with a one-line statement like this. In order to change the array 'haystack', the sorted values needs to be put back into the values array. I believe the best way to do this is with another for loop.