Platform
Resources
Pricing
Sign in
Get started
Sean Kelley
Workspace
Fork
Published
Snippets
By
Sean Kelley
Edited
May 28, 2020
Insert cell
Insert cell
Insert cell
time_series
=
{
while
(
true
)
{
yield
Promises
.
tick
(
100
,
Math
.
random
(
)
)
;
}
}
Insert cell
mutable
values
=
[
]
Insert cell
{
time_series
;
return
values
}
Insert cell
function
windowed_average
(
series
,
length
)
{
if
(
values
.
length
<
length
)
{
values
.
push
(
series
)
}
else
{
values
.
shift
(
)
values
.
push
(
series
)
}
const
sum
=
values
.
reduce
(
(
a
,
b
)
=>
a
+
b
,
0
)
;
const
avg
=
(
sum
/
values
.
length
)
||
0
;
return
avg
}
Insert cell
windowed_average
(
time_series
,
10
)
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
time_series
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
values
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
windowed_average
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML