1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export async function getTopTenBattingAverage() {
const data = await fetch(
"http://sports.core.api.espn.com/v2/sports/baseball/leagues/mlb/seasons/2024/types/2/leaders?lang=en&region=us",
);
const response = await data.json();
const promises = response.categories.find((cat) => cat.name === "avg").leaders.map((l) => l.athlete.$ref).slice(0, 10)
.map((
l,
) => fetch(l).then(response => response.json()));
const finalList = await Promise.all(promises);
const names = finalList.map((a, idx) => `${idx + 1}: ${a.fullName}`).join(", ");
return names;
}
const list = await getTopTenBattingAverage();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 26, 2024