I’m trying to sort an array of 6 integers in descending order(javascript) but keep matching values in their place as the other values are sorted. An example is posted below to help explain this problem:
Input: 4, 2, 5, 4, 7, 3
Output: 4, 7, 5, 4, 3, 2
Another Example with multiple matching values:
Input: 3, 4, 3, 4, 2, 8
Output: 3, 4, 3, 4, 8, 2
If there is no matching values:
Input:
6, 2, 9, 5, 3, 4
Output:
9, 6, 5, 4, 3, 2
First you would need to check whether if any values values match, and which values match. I’m not exactly sure how to do this in this context. I’m also not sure how to sort all the other values in the array other than the matching ones. Thanks in advance!
I tried running a for loop for the length of the array that checks every number to see whether there are any matches but this caused repeated values and doesn’t get any closer to the solution
Trew Smith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.