Platform
Resources
Pricing
Sign in
Get started
Periscopic
The socially conscious data visualization firm. We turn data into interactive visual experiences for empathy and understanding.
Workspace
Fork
Unlisted
By
Zach Bogart
Edited
May 26, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// function for accessing data
async
function
getFacts
(
{
animal
,
amount
}
)
{
let
response
=
await
fetch
(
`https://cat-fact.herokuapp.com/facts/random?animal_type=${
animal
}&amount=${
amount
}`
)
;
return
await
response
.
json
(
)
;
}
Insert cell
// make an array of api params
calls
=
[
{
animal
:
"cat"
,
amount
:
5
}
,
{
animal
:
"dog"
,
amount
:
5
}
,
{
animal
:
"horse"
,
amount
:
5
}
,
]
Insert cell
Insert cell
// map and flatten through array of parameters
(
await
Promise
.
all
(
calls
.
map
(
getFacts
)
)
)
.
flat
(
)
Insert cell
Insert cell
// function for accessing data
function
getFactsTest
(
animal
,
amount
)
{
let
baseUrl
=
`https://cat-fact.herokuapp.com/facts/random?animal_type=${
animal
}&amount=${
amount
}`
return
d3
.
json
(
baseUrl
)
}
Insert cell
// make an array of api params
callsTest
=
[
{
animal
:
"cat"
,
amount
:
5
}
,
{
animal
:
"dog"
,
amount
:
5
}
,
{
animal
:
"horse"
,
amount
:
5
}
,
]
Insert cell
Insert cell
// map through array of parameters
promisesTest
=
callsTest
.
map
(
d
=>
getFactsTest
(
d
.
animal
,
d
.
amount
)
)
Insert cell
// resolve promises
resultTest
=
Promise
.
all
(
promisesTest
)
Insert cell
// flatten
resultTest
.
flat
(
)
Insert cell
Insert cell
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getFacts
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
calls
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getFactsTest
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
callsTest
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
promisesTest
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
resultTest
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML