Platform
Resources
Pricing
Sign in
Get started
Jo Wood
Professor of Visual Analytics interested in design, geovisualization, visual storytelling and computational thinking.
Workspace
Fork
Public
Hello
By
Jo Wood
Edited
May 25, 2022
Hello
Hello Observable
Hello Polygons
Hello Transforms
Hello Animation
Hello Plot layout with HTML and CSS
Hello modern colour spaces
Hello Colour Mixing
Hello custom marks with Plot
Hello Polygon Morphing
Hello Zoom-Pan
Hello VegaLite and Vega
Hello Zoomable Vega-Lite Map
Hello Sketchy
Hello ClipperLib
Hello Network
Hello Linear Programming
Hello Census 2021
Hello Labella
Hello function expressions
Insert cell
Insert cell
myPoints
=
[
[
10
,
10
]
,
[
15
,
10
]
,
[
20
,
20
]
]
Insert cell
Insert cell
function
totalCost1
(
locations
)
{
let
total
=
0
;
let
prev
=
locations
[
0
]
;
for
(
let
i
=
0
;
i
<
locations
.
length
;
i
++
)
{
total
+=
cost
(
prev
,
locations
[
i
]
)
;
prev
=
locations
[
i
]
;
}
return
total
;
}
Insert cell
function
cost
(
[
x0
,
y0
]
,
[
x1
,
y1
]
)
{
return
Math
.
abs
(
x0
-
x1
)
+
Math
.
abs
(
y0
-
y1
)
;
}
Insert cell
totalCost1
(
myPoints
)
Insert cell
Insert cell
function
totalCost2
(
locations
)
{
const
cost
=
(
[
x0
,
y0
]
,
[
x1
,
y1
]
)
=>
Math
.
abs
(
x0
-
x1
)
+
Math
.
abs
(
y0
-
y1
)
;
let
total
=
0
;
let
prev
=
locations
[
0
]
;
for
(
let
i
=
0
;
i
<
locations
.
length
;
i
++
)
{
total
+=
cost
(
prev
,
locations
[
i
]
)
;
prev
=
locations
[
i
]
;
}
return
total
;
}
Insert cell
totalCost2
(
myPoints
)
Insert cell
Insert cell
Insert cell
Insert cell
function
totalCost3
(
locations
)
{
const
cost
=
(
[
x0
,
y0
]
,
[
x1
,
y1
]
)
=>
Math
.
abs
(
x0
-
x1
)
+
Math
.
abs
(
y0
-
y1
)
;
return
locations
.
reduce
(
(
[
total
,
prev
]
,
current
)
=>
[
total
+
cost
(
prev
,
current
)
,
current
]
,
// Reducing function
[
0
,
locations
[
0
]
]
// Initial total and 'previous' values
)
[
0
]
;
}
Insert cell
totalCost3
(
myPoints
)
Insert cell
Insert cell
Insert cell
Insert cell
function
totalCost4
(
locations
,
cost
=
(
[
x0
,
y0
]
,
[
x1
,
y1
]
)
=>
Math
.
abs
(
x0
-
x1
)
+
Math
.
abs
(
y0
-
y1
)
)
{
return
locations
.
reduce
(
(
[
total
,
prev
]
,
loc
)
=>
[
total
+
cost
(
prev
,
loc
)
,
loc
]
,
[
0
,
locations
[
0
]
]
)
[
0
]
;
}
Insert cell
Insert cell
totalCost4
(
myPoints
)
Insert cell
Insert cell
totalCost4
(
myPoints
,
(
p1
,
p2
)
=>
Math
.
hypot
(
...
p1
,
...
p2
)
)
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
myPoints
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
totalCost1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cost
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
totalCost2
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
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
totalCost3
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
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
totalCost4
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML