I've got the following array:
Array (3)
0 {_id: "5fea07cd143fd50008ae1ab2", newBalance: 1500, balanceDate: "2020-12-28T16:29:00.391Z"}
1 {_id:"5fea0837b2a0530009f3886f", newBalance: 1115, balanceDate: "2020-12-28T16:30:45.217Z"}
2 {_id: "5fec30faef904e0dd1e39c60", newBalance: 1415, balanceDate: "2020-12-30T07:49:13.214Z"}
I then have the following function, which maps through this array and picks out the newBalance from each of them. It then takes the previous value and subtracts the current value to work out the difference:
const diffs = debtBalance.map((item, index) =>
index === 0 ? 0 : debtBalance[index - 1].newBalance - item.newBalance
);
This outputs the following:
Array (3)
0 0
1 385
2 -300
What I then want to do is in examples like the second entry in the array (-300), take that value and separate out the '-' and the int, then in between them place a '£' sign.
So then if I log the updated array, the output would look like:
// 0, 385, -£300
I'm fine with the conditionals, this is working and I can pick out the figures, I just need to make the change to figures with a '-' before them and add a '£' in between.
Any feedback would be appreciated! :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…