Skip to content

Instantly share code, notes, and snippets.

Hunter Cassidy hunterc

Block or report user

Report or block hunterc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@developit
developit / async-examples.js
Last active Jul 24, 2019
Async Array utilities in async/await. Now available as an npm package: https://github.com/developit/asyncro
View async-examples.js
/** Async version of Array.prototype.reduce()
* await reduce(['/foo', '/bar', '/baz'], async (acc, v) => {
* acc[v] = await (await fetch(v)).json();
* return acc;
* }, {});
*/
export async function reduce(arr, fn, val, pure) {
for (let i=0; i<arr.length; i++) {
let v = await fn(val, arr[i], i, arr);
if (pure!==false) val = v;
You can’t perform that action at this time.