Skip to content

Instantly share code, notes, and snippets.

@scaleflake
Last active December 19, 2018 11:53
Show Gist options
  • Save scaleflake/a238a4196a2a476e98bf0edfeebe1ac0 to your computer and use it in GitHub Desktop.
Save scaleflake/a238a4196a2a476e98bf0edfeebe1ac0 to your computer and use it in GitHub Desktop.
Math.getRandomInt = (min, max) => {
/* getRandomInt(11, 17) => output includes 11 and 17 */
return Math.floor(Math.random() * (max - min + 1)) + min;
};
// Vue.js Nurislam Node.js Artur Islam React_Na Artur
// books[0].authors[0].books[1].authors[1] === persons[2].books[0].authors[1];
function fetchBooks() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([{
uid: `a`,
title: `Vue.js`,
authors: [0]
}, {
uid: `b`,
title: `React Native`,
authors: [1, 2]
}, {
uid: `c`,
title: `Node.js`,
authors: [0, 1]
}, {
uid: `d`,
title: `PHP 7.1`,
authors: [1, 2]
}]);
}, Math.getRandomInt(300, 500));
});
}
function fetchPersons() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([{
uid: `a`,
name: `Nurislam`,
books: [0, 2]
}, {
uid: `b`,
name: `Artur`,
books: [1, 2, 3]
}, {
uid: `c`,
name: `Islam`,
books: [1, 3]
}]);
}, Math.getRandomInt(200, 400));
});
}
// ur code here
async function _books() {
const books = await fetchBooks();
// or/and here
}
async function _persons() {
const persons = await fetchPersons();
// or/and here
}
async function main() {
setTimeout(_books, Math.getRandomInt(100, 200));
setTimeout(_persons, Math.getRandomInt(100, 200));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment