Both variables storing same values when programmatically they shouldn't

Hi Guys,

I’m building a split expenses app and right now it is at the basic level where I’m just trying to get the MVP running before scaling it.
I’ve hit dead end after running splitExpenses function. So basically I have an array of objects with a key called outstandingAmount.

I want to extract the the objects which contains the highest and lowest outstandingAmount amount value and save them in highestObj and lowestObj variable.

The problem is that these 2 variable are storing the same object when ideally highestObj should save object with outstandingAmount value as 135 and other with -135. And I can’t figure out why so I need your help here.

Please check the javaScript code from line 49-108 where all the action is. Ignore the code above line 49. Here is the codesandbox link for the same: .

Thanks in advance guys. :slight_smile:

In your find callbacks you are assigning to the object

elem.outstandingAmount = highestOutstanding

I assume you meant checking if the amount match.

find(element => elem.outstandingAmount === highestOutstanding)

Hope this helps :+1:

1 Like

OMG! I feel so stupid!
I have been trying to figure it out since yesterday!

Thank you so much @Marmiz.