2024-02-04T06:25:10.413Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
c10eeb61-56c4-4477-9ab5-9b4dbce3a55c
2e2a3118025fd3d7e9aeded3d75aef5dec5df1c5a9cc9751ea9a0db614762ad9
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
Array reduce.
Start with a list of items, then iterate over them to compute a single value.
It works just like basic arithmetic.
Consider 1 plus 2 plus 3.
What we have here is a list of numbers.
They're reduced to a single value using a function called addition.
In arithmetic, we go from left to right.
The result of the first computation is then added to the next one.
So it's actually just a loop, but a loop with a memory.
Take for example an array of orders from our online store.
Our goal is to calculate the total dollar amount of Sales across all of the orders in this array.
One option is to create a variable that starts at 0, then we'll start a For Loop and increment this value for each order total.
Reduce can solve the same type of problem, but without mutating the app state directly.
It does this by applying a reducer function to each each element in that array.
Your job is to define the reducer function.
The signature of that function has 2 required positional arguments, the first one being the accumulator.
That's just a fancy word for the last value that you returned from this function.
The second argument represents the current element in the loop, or in our case, an Order object.
The way we change the accumulated or remembered value is to return a value from the function.
To combine all of the order totals into a single number, we We simply add the accumulated value to the current value.
And, optionally, we can add a starting value as a second argument, which we'll set at 0.
The end result is the combined order total across all elements in the array.
We started with many things and reduced it down to one thing.
In some cases, you might want to start at the end of the array and work your way backwards.
You can use reduce right to start at the end of the array and work your way to the beginning.
This has been ArrayReduce in 100 seconds.
Thanks for watching and I will see you in the next one.

Speaker 0: Array reduce. Start with a list of items, then iterate over them to compute a single value. It works just like basic arithmetic. Consider 1 plus 2 plus 3. What we have here is a list of numbers.

They're reduced to a single value using a function called addition. In arithmetic, we go from left to right. The result of the first computation is then added to the next one. So it's actually just a loop, but a loop with a memory. Take for example an array of orders from our online store.

Our goal is to calculate the total dollar amount of Sales across all of the orders in this array. One option is to create a variable that starts at 0, then we'll start a For Loop and increment this value for each order total. Reduce can solve the same type of problem, but without mutating the app state directly. It does this by applying a reducer function to each each element in that array. Your job is to define the reducer function.

The signature of that function has 2 required positional arguments, the first one being the accumulator. That's just a fancy word for the last value that you returned from this function. The second argument represents the current element in the loop, or in our case, an Order object. The way we change the accumulated or remembered value is to return a value from the function. To combine all of the order totals into a single number, we We simply add the accumulated value to the current value.

And, optionally, we can add a starting value as a second argument, which we'll set at 0. The end result is the combined order total across all elements in the array. We started with many things and reduced it down to one thing. In some cases, you might want to start at the end of the array and work your way backwards. You can use reduce right to start at the end of the array and work your way to the beginning.

This has been ArrayReduce in 100 seconds. Thanks for watching and I will see you in the next one.
Array reduce. Start with a list of items, then iterate over them to compute a single value. It works just like basic arithmetic. Consider 1 plus 2 plus 3. What we have here is a list of numbers. They're reduced to a single value using a function called addition. In arithmetic, we go from left to right. The result of the first computation is then added to the next one. So it's actually just a loop, but a loop with a memory. Take for example an array of orders from our online store. Our goal is to calculate the total dollar amount of Sales across all of the orders in this array. One option is to create a variable that starts at 0, then we'll start a For Loop and increment this value for each order total. Reduce can solve the same type of problem, but without mutating the app state directly. It does this by applying a reducer function to each each element in that array. Your job is to define the reducer function. The signature of that function has 2 required positional arguments, the first one being the accumulator. That's just a fancy word for the last value that you returned from this function. The second argument represents the current element in the loop, or in our case, an Order object. The way we change the accumulated or remembered value is to return a value from the function. To combine all of the order totals into a single number, we We simply add the accumulated value to the current value.
sales
mathematics
revenue
solutions
programming
operations
earnings
accounting
And, optionally, we can add a starting value as a second argument, which we'll set at 0.
The end result is the combined order total across all elements in the array. We started with many things and reduced it down to one thing. In some cases, you might want to start at the end of the array and work your way backwards. You can use reduce right to start at the end of the array and work your way to the beginning.
operations
This has been ArrayReduce in 100 seconds. Thanks for watching and I will see you in the next one.
Array reduce. Start with a list of items, then iterate over them to compute a single value. It works just like basic arithmetic. Consider 1 plus 2 plus 3. What we have here is a list of numbers. They're reduced to a single value using a function called addition. In arithmetic, we go from left to right. The result of the first computation is then added to the next one. So it's actually just a loop, but a loop with a memory. Take for example an array of orders from our online store. Our goal is to calculate the total dollar amount of Sales across all of the orders in this array. One option is to create a variable that starts at 0, then we'll start a For Loop and increment this value for each order total. Reduce can solve the same type of problem, but without mutating the app state directly. It does this by applying a reducer function to each each element in that array. Your job is to define the reducer function. The signature of that function has 2 required positional arguments, the first one being the accumulator. That's just a fancy word for the last value that you returned from this function. The second argument represents the current element in the loop, or in our case, an Order object. The way we change the accumulated or remembered value is to return a value from the function. To combine all of the order totals into a single number, we We simply add the accumulated value to the current value. And, optionally, we can add a starting value as a second argument, which we'll set at 0. The end result is the combined order total across all elements in the array. We started with many things and reduced it down to one thing. In some cases, you might want to start at the end of the array and work your way backwards. You can use reduce right to start at the end of the array and work your way to the beginning. This has been ArrayReduce in 100 seconds. Thanks for watching and I will see you in the next one.
Array
array
reduce.
reduce
Start
start
with
with
a
a
list
list
of
of
items,
items
then
then
iterate
iterate
over
over
them
them
to
to
compute
compute
a
a
single
single
value.
value
It
it
works
works
just
just
like
like
basic
basic
arithmetic.
arithmetic
Consider
consider
1
1
plus
plus
2
2
plus
plus
3.
3
What
what
we
we
have
have
here
here
is
is
a
a
list
list
of
of
numbers.
numbers
They're
they're
reduced
reduced
to
to
a
a
single
single
value
value
using
using
a
a
function
function
called
called
addition.
addition
In
in
arithmetic,
arithmetic
we
we
go
go
from
from
left
left
to
to
right.
right
The
the
result
result
of
of
the
the
first
first
computation
computation
is
is
then
then
added
added
to
to
the
the
next
next
one.
one
So
so
it's
it's
actually
actually
just
just
a
a
loop,
loop
but
but
a
a
loop
loop
with
with
a
a
memory.
memory
Take
take
for
for
example
example
an
an
array
array
of
of
orders
orders
from
from
our
our
online
online
store.
store
Our
our
goal
goal
is
is
to
to
calculate
calculate
the
the
total
total
dollar
dollar
amount
amount
of
of
Sales
sales
across
across
all
all
of
of
the
the
orders
orders
in
in
this
this
array.
array
One
one
option
option
is
is
to
to
create
create
a
a
variable
variable
that
that
starts
starts
at
at
0,
0
then
then
we'll
we'll
start
start
a
a
For
for
Loop
loop
and
and
increment
increment
this
this
value
value
for
for
each
each
order
order
total.
total
Reduce
reduce
can
can
solve
solve
the
the
same
same
type
type
of
of
problem,
problem
but
but
without
without
mutating
mutating
the
the
app
app
state
state
directly.
directly
It
it
does
does
this
this
by
by
applying
applying
a
a
reducer
reducer
function
function
to
to
each
each
each
each
element
element
in
in
that
that
array.
array
Your
your
job
job
is
is
to
to
define
define
the
the
reducer
reducer
function.
function
The
the
signature
signature
of
of
that
that
function
function
has
has
2
2
required
required
positional
positional
arguments,
arguments
the
the
first
first
one
one
being
being
the
the
accumulator.
accumulator
That's
that's
just
just
a
a
fancy
fancy
word
word
for
for
the
the
last
last
value
value
that
that
you
you
returned
returned
from
from
this
this
function.
function
The
the
second
second
argument
argument
represents
represents
the
the
current
current
element
element
in
in
the
the
loop,
loop
or
or
in
in
our
our
case,
case
an
an
Order
order
object.
object
The
the
way
way
we
we
change
change
the
the
accumulated
accumulated
or
or
remembered
remembered
value
value
is
is
to
to
return
return
a
a
value
value
from
from
the
the
function.
function
To
to
combine
combine
all
all
of
of
the
the
order
order
totals
totals
into
into
a
a
single
single
number,
number
we
we
We
we
simply
simply
add
add
the
the
accumulated
accumulated
value
value
to
to
the
the
current
current
value.
value
And,
and
optionally,
optionally
we
we
can
can
add
add
a
a
starting
starting
value
value
as
as
a
a
second
second
argument,
argument
which
which
we'll
we'll
set
set
at
at
0.
0
The
the
end
end
result
result
is
is
the
the
combined
combined
order
order
total
total
across
across
all
all
elements
elements
in
in
the
the
array.
array
We
we
started
started
with
with
many
many
things
things
and
and
reduced
reduced
it
it
down
down
to
to
one
one
thing.
thing
In
in
some
some
cases,
cases
you
you
might
might
want
want
to
to
start
start
at
at
the
the
end
end
of
of
the
the
array
array
and
and
work
work
your
your
way
way
backwards.
backwards
You
you
can
can
use
use
reduce
reduce
right
right
to
to
start
start
at
at
the
the
end
end
of
of
the
the
array
array
and
and
work
work
your
your
way
way
to
to
the
the
beginning.
beginning
This
this
has
has
been
been
ArrayReduce
arrayreduce
in
in
100
100
seconds.
seconds
Thanks
thanks
for
for
watching
watching
and
and
I
i
will
will
see
see
you
you
in
in
the
the
next
next
one.
one
success
The speaker explains how to reduce the number of items in a list and use a function called addition to compute the total dollar amount of Sales across all orders. They also explain how to define the reducer function and how to work backwards to combine all the order totals into a single number. The speaker emphasizes that reducing the number of items is a fancy way to reduce time and provides a reference code for the next video.
Array Reduce in 100 seconds
Learn JavaScript's Array Reduce method in 100 seconds. Take many things and reduce them down to one thing. 

#JavaScript #100SecondsOfCode

Array Reduce: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

Install the quiz app 🤓

iOS https://itunes.apple.com/us/app/fireship/id1462592372?mt=8
Android https://play.google.com/store/apps/details?id=io.fireship.quizapp

Upgrade to Fireship PRO at https://fireship.io/pro
Use code lORhwXd2 for 25% off your first payment. 

My VS Code Theme

- Atom One Dark 
- vscode-icons
- Fira Code Font