I have an array of object containing colors. I need to sort the array by the color in a specific order.
I used the answer from stackoverflow to sort the array in a specific order and it has mostly worked. The issue that I face right now is that when I visualise it using D3Js, instead of clubbing all the objects with matching colors together there is repetition of the colors in specified order. Why is this happening and how can I get the correct sorting.
var sortOrder = {"#F39849": 0, "#E94927": 1, "#538296": 2, "#CCCCCC": 3};
var sortedData = data.sort(function (p1, p2) {
return sortOrder[p1.colors] - sortOrder[p2.colors];
});
full code is here