Hey there,
Hope someone can give me a hand.
That function I have:
let formattedOutput = [];
let tempArray = [];
let chunkSize = 4; // Each game has 4 elements (time, hometeam, awayteam, channel)
for (let i = 0; i < msg.payload.length; i++) {
tempArray.push(msg.payload[i]);
if ((i + 1) % chunkSize === 0) {
formattedOutput.push(tempArray);
tempArray = [];
}
}
let finalOutput = formattedOutput.map(game => {
return game[0] + " " + game[1] + " VS " + game[2] + " " + game[3];
});
msg.payload = finalOutput.join('\n');
return msg;
Outputs a string:
msg.payload : string[6619]
" 18:45 Portimonense FC Porto SPORT TV1 19:00 Go Ahead Eagles PSV SPORT TV2 19:30 Estugarda Union Berlin ELEVEN SPORTS 2 19:30 SD Huesca FC Andorra ELEVEN SPORTS 5 19:45 Napoli Torino SPORT TV4 20:00 Barcelona Mallorca ELEVEN SPORTS 1 20:00 Nice Montpellier ELEVEN SPORTS 4 20:45 CF Estrela Amadora Casa Pia SPORT TV2 20:45 U. Leiria SAD Oliveirense SPORT TV3 22:00 Caxias SĂŁo JosĂ©-RS PFC 11:00 FC Porto S19 Benfica S19 PORTO CANAL 11:00 Mafra Penafiel SPORT TV1 11:00 Sp. Braga FM Lank Vilaverdense FM CANAL 11 11:00 Sporting S17 V. GuimarĂŁes S17 SPORTING TV 12:00 Holstein Kiel Karlsruher ELEVEN SPORTS 4 12:00 Schalke 04 SC Paderborn 07 ELEVEN SPORTS 3 12:30 Man Utd Everton ELEVEN SPORTS 1 13:00 ValĂȘncia Getafe ELEVEN SPORTS 2 14:00 Nacional Ac. Viseu SPORT TV+ 14:30 Bayern MĂŒnchen Mainz ELEVEN SPORTS 3 14:30 RB Leipzig SV Darmstadt 98 ELEVEN SPORTS 4 15:00 Torreense FM Sporting FM SPORT TV6 15:00 V. ..."
What I want it to do, is to output as arrays; every time there's a format "hh:mm", it creates a new array.
Something like:
array[1]
18:45 Portimonense Vs FC Porto SPORT TV1
array[2]
19:00 Go Ahead Eagles Vs PSV SPORT TV2
array[3]
19:30 Estugarda Vs Union Berlin ELEVEN SPORTS 2
array[4]
19:30 SD Huesca Vs FC Andorra ELEVEN SPORTS 5
array[5]
19:45 Napoli Vs Torino SPORT TV4
...
Any ideas?