Modifying strings in an array of strings with duplicate keys with Javascript

I’m stuck on a codewars kata on the final step where I need to modify an array’s strings and sum the value of duplicate keys. res=[ '(A : 200)', '(B : 250)', '(B : 890)' ] should be modified into res=[ '(A : 200)', '(B : 1140)']

I figured out how to select the portion of the string that I want to sum with res.forEach((x, i) => { x.slice(5, -1)}) but I am absolutely stuck on how to write out and check if x[1] appears more than once and how to create a new array that reassigns that specific element by the summation of its Number(string slice).

Please help !

42 thoughts on “Modifying strings in an array of strings with duplicate keys with Javascript”

Leave a Comment