I have the following arrays:
array_order = [ 'SiteA', 'SiteC', 'SiteB' ]
string_array = [
[ 'Site C', 'StringC1_' ] ,
[ 'Site A', 'StringA1_' ] ,
[ 'Site C', 'StringC2_' ] ,
[ 'Site B', 'StringB1_' ] ,
[ 'Site B', 'StringB2_' ] ,
[ 'Site B', 'StringC3_' ] ,
[ 'Site B', 'StringA2_' ]
]
I want to group the strings by site and output them as a concatenated string in order of array_order, so something like this:
output = [ 'StringA1_StringA2_', 'StringC1_StringC2_StringC3_', 'StringB1_StringB2_' ]
The concatenation order doesn't matter, for example 'StringA1StringA2' is just as fine as 'StringA2StringA1' so I don't need to worry about sorting them.
I was initially thinking I could convert string_array to an object, then somehow concatenate by group, then map it something like array_order.map(key => obj[key]) but I am struggling with making an object to be iterated and concatenated.
StringC3_supposed to be under "Site B"?, as you grouping by the letterCfound in the string or by the "Site"?array_orderyou do not have space in group name, but instring_arrayyou do[ 'Site B', 'StringC3_' ]