I'm have an object as shown below for which I need to find the total including the numbers that are outside as well as inside the curly braces.
this.count = {
"count1": "250 (220)",
"count2": "125 (100)",
"count3": "125 (100)",
"count4": "125 (100)"
}
Expected result: Sum : "625 (520)"
I was able t find out the sum of the first set of strings ie., 625 by doing below logic:
let total=this.getTotal(this.count);
public getTotal(count) {
const count1 = parseInt(items.count1.split(' ')[0]);
const count2 = parseInt(items.count2.split(' ')[0]);
const count3 = parseInt(items.count3.split(' ')[0]);
const count4 = parseInt(items.count4.split(' ')[0]);
const totalA = count1 + count2 + count3 + count4;
console.log(totalA);
}
But I was not able to split wisely ()
to calculate the other portion and concate with totalA
.Do let me know any functional approach that suits best to calculate these type of objects.Thanks