JSFiddle - React, Tailwind, and code Playground

by r3wt

HTML

<div id="result">

</div>

JavaScript

var sync = function( items, eachFn, callbackFn ){
	
	var results = [], 
		errors = [];
		
	function next(error,result){
		if([null,undefined].indexOf(error) != -1) errors.push(error);
		if(result != undefined) results.push(result);
		if(items.length == 0){
			return callbackFn(errors,results);
		}else{
			//pop first item, pass it to eachCb with the next function
			eachFn(items.shift(),next);
		}
	};
	
	eachFn(items.shift(),next);
	
};

var array = new Array(1000).fill(0);// 1000 item array
var i = -1;
sync(array,function(item,next){
	i++;
	next(null,i);
},function(errors,results){
	document.getElementById('result').innerHTML = results.length;
});