This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
<ul> | |
<li v-for='number in numbers' :key='number'>{{ number }}</li> | |
</ul> | |
<form @submit.prevent='addNumber'> | |
<input type='text' v-model='newNumber'> | |
<button type='submit'>Add another number</button> | |
</form> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extend the Array prototype with an asyncForEach method | |
Array.prototype.asyncForEach = async function (fn) { | |
for (let i = 0; i < this.length; i++) { | |
await fn(this[i], i); | |
} | |
}; | |
const arr = ['a', 'b', 'c', 'd']; | |
// define a Promise wrapper around the setTimeout function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define a Promise wrapper around the setTimeout function | |
function wait (fn, time) { | |
return new Promise(resolve => setTimeout(() => {fn();resolve();}, time)); | |
} | |
const arr = ['a', 'b', 'c', 'd']; | |
// if we want to call an async function for each element in the array | |
// in series, this would not work: | |
arr.forEach(async (item, index) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const cols = 8; | |
function randomChar () { | |
return String.fromCharCode(Math.floor(Math.random() * (122-65) + 65)); | |
} | |
function randomString (length) { | |
let string = ''; |
NewerOlder