Skip to content

Instantly share code, notes, and snippets.

@harsilspatel
Created October 8, 2018 07:52
Show Gist options
  • Save harsilspatel/8cd5fe05c047c6ede730774bde543a92 to your computer and use it in GitHub Desktop.
Save harsilspatel/8cd5fe05c047c6ede730774bde543a92 to your computer and use it in GitHub Desktop.
a snippet to perform delayed execution of a given function on each element of the array Raw
forEachDelayed = (arr, interval, f) => {
arr.forEach((item, index) => {
setTimeout(() => {
f(item);
}, index * interval);
});
};
// forEachDelayed(['a','b','c','d'], console.log, 1000)
//> a (immediately)
//> b (after 1 second)
//> c (after 2 seconds)
//> d (after 3 seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment