JSFiddle - React, Tailwind, and code Playground

by jpeter06

HTML

<textarea id="salida" rows="14">
  SALIDA
</textarea>

JavaScript

var result = "";
var textArea = document.getElementById('salida');
textArea.val = "COMIENZO";
var debounce = (fn, delay) =>{
	let timer;
  return (...args) =>{
  	clearTimeout(timer);
    timer = setTimeout(()=>fn(...args),delay);
  };
};

const myFunc = (text) => {result += text + '\n'; textArea.value = result};
const myDebounceFunc = debounce(myFunc, 1000);

//10 times
for(let i = 0;  i < 10; i++) myFunc("NOT DEB");
//10 times , debounced
for( let i = 0; i < 10; i++) {
	myDebounceFunc("DEB!");
}