Вы можете использовать уменьшение массива, чтобы получить пользователя, который меньше платил, и объединиться с Promise.all, используя async / await для получения всех пользовательских данных
'use strict';
/* mock data for testing purposes
const usersData = [{
name: 'john doe',
payed: 10,
}, {
name: 'john doe01',
payed: 5,
}, {
name: 'john doe02',
payed: 8,
}, {
name: 'john doe03',
payed: 20,
}, {
name: 'john doe04',
payed: 40,
}, {
name: 'john doe05',
payed: 37,
}];
*/
async function getUsers() {
const usersResponse = await Promise.all(
usersName.map(userName => fetch(`http://something.something?q=${userName}`))
);
return usersResponse.map(userResponse => userResponse.json());
}
async function init() {
try {
const usersName = [
'tom',
'jenny',
'smith',
'Joe',
];
const usersData = await getUsers(usersName);
const userWhoLessPayed = usersData.reduce((prevUser, currentUser) => {
if (prevUser.payed > currentUser.payed) {
return currentUser;
}
return prevUser;
});
console.log(userWhoLessPayed);
} catch (e) {
console.error(e);
}
}
init();