Dado este guión
<script> var sentences= [ ['journey27.mp4', [ [1, 2], [5, 7] ] ], ['journey28.mp4', [ [10, 12], [13, 17], [25, 36] ] ], ['journey30.mp4', [ [13, 15], [15, 19] ] ] ]; function playVideo(myUrl, startTime, endTime) { console.log(`Playing ${myUrl} from ${startTime} to ${endTime}`); } function myLoop(){ //what should I fill in here? } </script>Quiero imprimir este resultado:
Reproduciendo 'journey27.mp4' del 1 al 2
Reproduciendo 'journey27.mp4' del 1 al 2
Reproduciendo 'journey27.mp4' del 1 al 2
Reproduciendo 'journey27.mp4' del 5 al 7
Reproduciendo 'journey27.mp4' del 5 al 7
Reproduciendo 'journey27.mp4' del 5 al 7
Reproduciendo 'journey28.mp4' de 10 a 12
Reproduciendo 'journey28.mp4' de 10 a 12
Reproduciendo 'journey28.mp4' de 10 a 12
Reproduciendo 'journey28.mp4' del 13 al 17
Reproduciendo 'journey28.mp4' del 13 al 17
Reproduciendo 'journey28.mp4' del 13 al 17
Reproduciendo 'journey28.mp4' del 25 al 36
Reproduciendo 'journey28.mp4' del 25 al 36
Reproduciendo 'journey28.mp4' del 25 al 36
Reproduciendo 'journey30.mp4' del 13 al 15
Reproduciendo 'journey30.mp4' del 13 al 15
Reproduciendo 'journey30.mp4' del 13 al 15
Reproduciendo 'journey30.mp4' del 15 al 19
Reproduciendo 'journey30.mp4' del 15 al 19
Reproduciendo 'journey30.mp4' del 15 al 19
Nota : cada línea del subarreglo debe reproducirse 3 veces y luego pasa a la siguiente línea.
¿Cómo puedo completar la función myLoop para imprimir el resultado anterior?
Puedes probar este enfoque
var data = [ ['journey27.mp4', [ [1, 2], [5, 7] ] ], ['journey28.mp4', [ [10, 12], [13, 17], [25, 36] ] ], ['journey30.mp4', [ [13, 15], [15, 19] ] ] ]; function playVideo(myUrl, startTime, endTime) { console.log(`Playing ${myUrl} from ${startTime} to ${endTime}`); } function myLoop(sentences, lineCount) { for (const sentence of sentences) { const [video, timers] = sentence //extract video url and the timer array for (const timer of timers) { const [startTime, endTime] = timer //extract start time and end time in each timer for (let i = 0; i < lineCount; i++) { playVideo(video, startTime, endTime) //console.log for each line } } } } const lineCount = 3 //will print 3 times myLoop(data, lineCount)