Skip to content
Advertisement

How to sort an array with special conditions

I just want to return an array containing the first and second objects based on the “point” property of an object

and I have a condition below, When the condition is satisfied it will swap places.

JavaScript

Given the following object:

JavaScript

the result I want is

JavaScript

Advertisement

Answer

You could group the data with an object for the indices and an array of references.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement