yodacom
5/10/2017 - 2:09 PM

3CBwithProgressBar created by yodacom - https://repl.it/HpJh/5

3CBwithProgressBar created by yodacom - https://repl.it/HpJh/5

// REQUIREMENTS: Writing a simple progress bar function in the callback style. Function takes three callbacks: onStart, onProgress, and onEnd as arguments. When you call the function it should call the onStart callback, then loop from 1 to 100, using console.log to print each value. Every 10 items it counts it should call the onProgress callback, providing how far along it is as an argument. Finally it should call the onEnd callback.

// SUDOCODE:
// First the function will call the onStart callback creating numbers from 1-100 and console.log the results 
 
// While creating the numbers onStart an onProgress callback will be called that will console.log display the number items, 10 at a time, as a % of 100 total being created toward total of 100 

// When onProgress reaches 100 then it will call the onEnd callback to stop.

// vincents code help:

// using my Array spread operator

function progressBar(onStart, onProgress, onDone){
  onStart();
  
  [...Array(100)]
    .map((_, i) => ++i)
    .filter((i)=>i % 10 === 0)
    .forEach((i)=>onProgress(i));
  
  onDone();
}

// using standard loop

function progressBarOld(onStart, onProgress, onDone){
  onStart();
  
  for(let i = 1; i <= 100; i++){
    if(i % 10 === 0){
      onProgress(i);
    }
  }
  
  onDone();
}



progressBarOld(function(){
  console.log('...%');
},
function(i){
  console.log(i + '%');
},
function(){
  console.log('Completed');
});


progressBar( 
  function(){console.log('Starting again');}, 
  function(i){console.log(i);}, 
  function(){ console.log('Done again')}
  );


// end Vincents code help

// function callbackProgBar(onStart, onProgress, onEnd) {
 	 
 	 var onStart = [...Array(100)].map((_, i) => ++i);
 	 onStart;

//}

// var onProgress =  function (onStart) {
// return num % 10 === 0;
// num push(onProgress)
// };

// var percentageProgress = myArray.filter(onProgress);


// var onEnd = function() {
//   onProgress = 10;
// };