'JavaScript sorting of an RGB array

This is the task:

Colors have to be ordered in such way:

  • Higher Red value first; if the same then:

  • Higher Green value first; if the same then:

  • Higher Blue value first; if the same then on the same position

The task is as follows. I don't know how to do it or what it is supposed to look like. Ideally, the function should take an array of colors in HEX. E.g:

  [

    "#FF1100",

    "#44FF00",

    "#1900FF",

    "#E02500",

    "#54E600",

    "#0206DE",

   ]

And then it returned the sorted array as in the task. How can I do it? I am stuck.



Solution 1:[1]

Simple sort with reverse should work:

yourData.sort().reverse()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Radu Diță