Let say I have
let arr = [
{code: 5, country: 'DE', price: 8},
{code: 6, country: 'RU', price: 9},
{code: 7, country: 'US', price: 10},
{code: "FiveX", country: 'UK', price: 11},
{code: 5, country: 'ES', price: 12},
{code: 5, country: 'RU', price: 13},
{code: 7, country: 'BE', price: 14},
]
I need this array to be reordered as follows
arr = [
{priceDE: '8 (code5)' , priceES: '12 (code5)', priceRU: '13 (code5)'},
{priceRU: '9 (code6)'},
{priceUS: '10 (code7)', priceBE: '14 (code7)'}
{priceUK: '11 (codeFiveX)'}
]
I basically need to group them with the code reference, but I dont really understand how to do it without knowing the value of code beforehand. Keep in mind that code isn't always a number it can be a string