I have an array of strings that need to be combined to form a single string, using a specific number referred to as the associatedNumber
. This associatedNumber
dictates that in the final result, all clusters of identical characters (from the array) should not exceed this associatedNumber
in length.
Illustrative Example
exampleOutput = [
'UUU', 'DD', 'UU',
'UU', 'SSS','A',
'B', 'C','U',
'Y'
]
The desired output is:
UUUDDUUUSSSABCUY
Current Approach
The approach being taken currently is:
output = [
'AAA', 'ZZZ', 'AA',
'AA', 'X', 'K',
'L', 'N', 'O',
'P'
]
associatedNumber = 3;
for (i = 0; i < output.length; i++) {
if (output[i] === associatedNumber);
output.splice(i,1);
}
console.log(output)
Different Scenario
output = [
'XXXX', 'GGG',
'GG', 'XXX',
'J', 'M',
'H'
]
This should result in:
XXXGGGXXXJMH