Platform
Resources
Pricing
Sign in
Get started
Evan Schultz
full-stack JavaScript fiddler. I build / talk / train about the stuff I like @rangle
Workspace
Fork
Published
Arrays
By
Evan Schultz
Edited
Oct 9, 2019
1 star
Insert cell
Insert cell
{
let
total
=
0
;
let
numbers
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
]
;
for
(
let
x
=
0
;
x
<
numbers
.
length
;
x
++
)
{
total
=
total
+
numbers
[
x
]
;
}
return
total
;
}
Insert cell
Insert cell
[
1
,
2
,
3
,
4
,
5
,
6
,
7
]
.
reduce
(
(
acc
,
value
)
=>
{
return
(
acc
+=
value
)
;
}
)
;
Insert cell
Insert cell
[
1
,
2
,
3
,
4
,
5
,
6
,
7
]
.
reduce
(
(
acc
,
value
)
=>
{
return
(
acc
+=
value
)
;
}
,
10
)
;
Insert cell
Insert cell
[
5
,
1
,
2
,
9
,
20
,
20
,
30
]
.
reduce
(
(
acc
,
value
)
=>
{
if
(
value
>=
10
)
{
acc
+=
value
;
}
return
acc
;
}
)
;
Insert cell
Insert cell
[
5
,
1
,
2
,
9
,
20
,
20
,
30
]
.
reduce
(
(
acc
,
value
)
=>
{
if
(
value
>=
10
)
{
acc
+=
value
;
}
return
acc
;
}
,
0
)
;
Insert cell
Insert cell
[
{
item
:
"Apples"
,
cost
:
5
}
,
{
item
:
"Eggs"
,
cost
:
2
}
]
.
reduce
(
(
acc
,
value
)
=>
{
return
acc
+
value
.
cost
;
}
)
;
Insert cell
Insert cell
[
{
item
:
"Apples"
,
cost
:
5
}
,
{
item
:
"Eggs"
,
cost
:
2
}
]
.
reduce
(
(
acc
,
value
)
=>
{
return
acc
+
value
.
cost
;
}
,
0
)
;
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
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
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
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML