I have the following object
const originalObject = {
width: 1090,
height: 723,
}
And this list of objects
const validObjects = [
{
width: 1080,
height: 1080
},
{
width: 1080,
height: 1350
},
{
width: 1080,
height: 750
}
]
Giving the following helper
const area = (width, height) => width * height;
I need to find the object from validObjects whose area most closely resembles that of the original object.
So if I do:
getMostSimilarObject(originalObject, validObjects)
I get:
{
width: 1080,
height: 750
}
as area(1080, 750) is the most close one to area(1090, 723)
Any ideas?
Note: In validObjects, there will only be around 3 to 10 objects.