Let me show you how I'm going to solve this challenge.
It says that, right, a function that takes in an array of numbers and returns the sum of all the numbers
in the array.
So come down here as my solution.
Solution here.
And here we go.
So counts.
Let me assign the sum of all numbers.
Every.
So I want to sum up these numbers.
Let's say one, two, five, six, nine, and they say two.
So I want to sum up these arrays of numbers.
So my function goes like this.
Function and then sum.
Copy this one.
Some.
Yeah.
This one some of some of our away numbers function.
And then I would it would take in the array.
And next is.
Here we go.
So here comes a logic we need to use reduce method to get this one done.
And how does it work?
So we can say that const twitter is equal to the array our pass in as that on that I will use reduce
and then remember I reduce our pass in my callback function.
And my parentheses.
The second argument is my initial variable value zero.
So here I have access to my accumulator and my my current element or current value.
In that.
So if I save it now up in my parentheses, then I will say that.
Well, retain.
Accumulator plus my current value.
That is it.
So this function must return the results coming back from this.
So after my reduced function down here, then I would say retain it, retain the total as that.
And that is that and that is it.
Right.
So let's check it out.
Let's assign the result.
Let me say cost and sum is equal to sum of all.
Every function I'll pass in sum of all arrays.
I think I have declared the answer somewhere else here.
Yeah.
I think the answer to.
Yeah.
No no no.
As and start to.
Okay so let's console.log the answer to.
There you go.
We have for the three if we add one plus this plus this plus this plus this is equal to the.
That is it about the function.
And this function can be simplified in a simple way.
So instead of doing this one this way, we can quickly let me comment out this maybe for future references.
So here I can do on one line by saying that I would take my array and then dot dot, reduce.
Then I'll pass in my function.
Brenda says.
And next is, if I'm returning something from this immediately, I can do it in this way on one line.
Don't worry, if you go about a random script, I will show you the syntax for this.
But I think every function.
Right.
But for the meantime, because we are not having to tackle about every function, this one will not
work for you, meaning you will not understand, but for advanced developers.
Okay, follow me.
So this one going to be.
And now here I can return a account plus the current.
And that is it.
You see, I still see the same result.
So this line of code can be simplified as this.
That is it the next video?
Let's have a look at our next coding challenge.