JSFiddle - React, Tailwind, and code Playground

by RomainMazB

HTML

<ul id="fakeConsole"></ul>

JavaScript

$(document).ready(function(){
  let methods = {
  	asyncMultiplyBy: (nb, multiplyBy) => {
  	return new Promise(resolve => setTimeout(() => resolve(nb * multiplyBy), 100));
  	},
    asyncDivideBy: (nb, divideBy) => {
      return new Promise(resolve => setTimeout(() => resolve(nb / divideBy), 100));
    }
  };
	let myVar = [2, 4, 6],
  		actionsToApply = [{asyncMultiplyBy: {nb: 2}}, {asyncDivideBy4: {nb: 4}}],
      newVal = [];
	
  
  async function modifyVal(nb, actions) {
    await Promise.all(Object.keys(actions).map(async (action) => { // Pass myVar threw all actions
      await methods[action](nb, parameters[parameter_name])
        .then((val) => {
        newVal = val;
      });
    }));
  }
  $("#fakeConsole").appendText(modifyVal
});