let array = Array.from({ length: 10 }, (v, k) => k)
const fn = (el) =>
setTimeout(() => {
console.log(el)
return el * 2;
},
1000 * Math.random()
)
console.log(array.map(fn))
arr = Array.from({ length: 10 }, (v, k) => k);
function timeout(val){
return new Promise((resolve, reject)=>{
setTimeout(()=>{
console.log(val);
resolve();
}, 1000 * Math.random());
});
}
(async () => {
for (const val of arr) {
await timeout(val);
}
console.log('Расчет окончен');
})();
let array = Array.from({ length: 10 }, (v, k) => k);
const fn = (el) => {
setTimeout(() => { console.log(el) }, 100 * el);
return el * 2;
};
console.log(array.map(fn));