const anyFetch = async () =>
fetch(url)
.then(arr => arr.map(
id => fetch(url + id)
));
const allData = Promise.All(anyFetch).then(arrOfFinishData => doSomething(arrOfFinishData));
const result = Object.values(data.reduce((acc, { id, color }) => (
(acc[id] ??= { id, colors: [] }).colors.push(color),
acc
), {}));
function group(data, key, val = n => n) {
const getKey = key instanceof Function ? key : n => n[key];
const getVal = val instanceof Function ? val : n => n[val];
const result = new Map;
for (const n of data) {
const k = getKey(n);
result.set(k, result.get(k) ?? []).get(k).push(getVal(n));
}
return result;
}
const result = Array.from(
group(data, 'id', 'color'),
([ id, colors ]) => ({ id, colors })
);
let func = require('./functions.js')
const controllerCheckInput = value =>
users.find({ login: value }).then(res => !!res);
// вариант async/await
(async () => {
const exists = await controllerCheckInput('login');
console.log(exists);
})();
// then/catch
(() => {
controllerCheckInput('login').then(exists => {
console.log(exists);
});
})();
// примерно так это выглядит в express
app.post('/register', async (req, res) => {
const exists = await controllerCheckInput('login');
console.log(exists);
});