task8/script.js
// Calculate rests to complete the 4/4 bar
Calculate rests to complete the 4/4 bar
Calculate rests to complete the 4 / 4 bar
function restsToComplete(notes) {
  let restsDuration = 16;
  let notesDuration = 0;
  for (let note of notes) {
    let noteDuration = calculateNoteDurationInSixteenth(note);
    console.log(noteDuration);
    notesDuration += noteDuration;
  }
  restsDuration -= notesDuration;
  let quarterRests = Math.floor(restsDuration / 4);
  let sixteenthRests = restsDuration % 4;
  let quarterRestsString = 'B4/4/r,'.repeat(quarterRests);
  let sixteenthRestsString = 'B4/16/r,'.repeat(sixteenthRests);
  return quarterRestsString + sixteenthRestsString; 
}
function restsToComplete ( notes ) { let restsDuration = 16 ; let notesDuration = 0 ; for ( let note of notes ) { let noteDuration = calculateNoteDurationInSixteenth ( note ) ; console . log ( noteDuration ) ; notesDuration += noteDuration ; } restsDuration -= notesDuration ; let quarterRests = Math . floor ( restsDuration / 4 ) ; let sixteenthRests = restsDuration % 4 ; let quarterRestsString = 'B4/4/r,' . repeat ( quarterRests ) ; let sixteenthRestsString = 'B4/16/r,' . repeat ( sixteenthRests ) ; return quarterRestsString + sixteenthRestsString ; }
Calculate rests to complete the 4/4 bar
Calculate rests to complete the 4 / 4 bar
// Initialize rest to the total of 16 notes // Initialize the duration of notes to zero // Loop over each note // Calculate the duration of the note // Update notes duration // Calculate what we need to use in rests // Stringify the value of our rests