1
00:00:00,270 --> 00:00:03,210
Let me show you how I'm going to solve this challenge.

2
00:00:03,240 --> 00:00:11,520
It says that, right, a function that takes in an array of numbers and returns the sum of all the numbers

3
00:00:11,520 --> 00:00:12,360
in the array.

4
00:00:12,660 --> 00:00:16,440
So come down here as my solution.

5
00:00:17,570 --> 00:00:19,100
Solution here.

6
00:00:19,130 --> 00:00:20,300
And here we go.

7
00:00:20,450 --> 00:00:21,660
So counts.

8
00:00:21,680 --> 00:00:27,440
Let me assign the sum of all numbers.

9
00:00:27,770 --> 00:00:28,490
Every.

10
00:00:28,790 --> 00:00:30,860
So I want to sum up these numbers.

11
00:00:30,860 --> 00:00:37,160
Let's say one, two, five, six, nine, and they say two.

12
00:00:37,550 --> 00:00:41,090
So I want to sum up these arrays of numbers.

13
00:00:41,480 --> 00:00:43,220
So my function goes like this.

14
00:00:43,250 --> 00:00:46,610
Function and then sum.

15
00:00:48,310 --> 00:00:49,240
Copy this one.

16
00:00:49,420 --> 00:00:50,440
Some.

17
00:00:52,320 --> 00:00:52,710
Yeah.

18
00:00:52,710 --> 00:00:57,540
This one some of some of our away numbers function.

19
00:00:58,140 --> 00:01:01,420
And then I would it would take in the array.

20
00:01:01,440 --> 00:01:02,710
And next is.

21
00:01:02,730 --> 00:01:03,780
Here we go.

22
00:01:04,500 --> 00:01:10,430
So here comes a logic we need to use reduce method to get this one done.

23
00:01:10,440 --> 00:01:12,420
And how does it work?

24
00:01:12,450 --> 00:01:24,750
So we can say that const twitter is equal to the array our pass in as that on that I will use reduce

25
00:01:25,860 --> 00:01:29,790
and then remember I reduce our pass in my callback function.

26
00:01:30,970 --> 00:01:33,640
And my parentheses.

27
00:01:33,640 --> 00:01:37,300
The second argument is my initial variable value zero.

28
00:01:37,660 --> 00:01:45,310
So here I have access to my accumulator and my my current element or current value.

29
00:01:46,930 --> 00:01:47,710
In that.

30
00:01:48,160 --> 00:01:53,170
So if I save it now up in my parentheses, then I will say that.

31
00:01:53,170 --> 00:01:55,390
Well, retain.

32
00:01:56,630 --> 00:02:00,200
Accumulator plus my current value.

33
00:02:00,830 --> 00:02:01,640
That is it.

34
00:02:01,790 --> 00:02:06,620
So this function must return the results coming back from this.

35
00:02:07,960 --> 00:02:20,200
So after my reduced function down here, then I would say retain it, retain the total as that.

36
00:02:20,470 --> 00:02:22,600
And that is that and that is it.

37
00:02:22,840 --> 00:02:23,530
Right.

38
00:02:23,530 --> 00:02:25,060
So let's check it out.

39
00:02:25,090 --> 00:02:27,580
Let's assign the result.

40
00:02:27,580 --> 00:02:34,180
Let me say cost and sum is equal to sum of all.

41
00:02:34,180 --> 00:02:38,260
Every function I'll pass in sum of all arrays.

42
00:02:39,580 --> 00:02:43,090
I think I have declared the answer somewhere else here.

43
00:02:44,760 --> 00:02:45,390
Yeah.

44
00:02:45,660 --> 00:02:45,990
Yeah.

45
00:02:45,990 --> 00:02:47,820
I think the answer to.

46
00:02:48,330 --> 00:02:48,640
Yeah.

47
00:02:48,660 --> 00:02:49,240
No no no.

48
00:02:49,560 --> 00:02:52,740
As and start to.

49
00:02:53,170 --> 00:02:56,700
Okay so let's console.log the answer to.

50
00:02:58,830 --> 00:02:59,760
There you go.

51
00:02:59,790 --> 00:03:05,730
We have for the three if we add one plus this plus this plus this plus this is equal to the.

52
00:03:06,240 --> 00:03:08,400
That is it about the function.

53
00:03:08,820 --> 00:03:12,870
And this function can be simplified in a simple way.

54
00:03:13,050 --> 00:03:19,200
So instead of doing this one this way, we can quickly let me comment out this maybe for future references.

55
00:03:19,350 --> 00:03:30,180
So here I can do on one line by saying that I would take my array and then dot dot, reduce.

56
00:03:31,050 --> 00:03:33,120
Then I'll pass in my function.

57
00:03:34,050 --> 00:03:35,250
Brenda says.

58
00:03:35,490 --> 00:03:43,330
And next is, if I'm returning something from this immediately, I can do it in this way on one line.

59
00:03:43,350 --> 00:03:46,980
Don't worry, if you go about a random script, I will show you the syntax for this.

60
00:03:47,220 --> 00:03:48,870
But I think every function.

61
00:03:48,870 --> 00:03:49,490
Right.

62
00:03:49,500 --> 00:03:55,560
But for the meantime, because we are not having to tackle about every function, this one will not

63
00:03:55,560 --> 00:04:01,470
work for you, meaning you will not understand, but for advanced developers.

64
00:04:01,560 --> 00:04:02,580
Okay, follow me.

65
00:04:02,610 --> 00:04:05,240
So this one going to be.

66
00:04:05,280 --> 00:04:10,680
And now here I can return a account plus the current.

67
00:04:11,220 --> 00:04:12,050
And that is it.

68
00:04:12,060 --> 00:04:14,660
You see, I still see the same result.

69
00:04:14,670 --> 00:04:18,060
So this line of code can be simplified as this.

70
00:04:19,380 --> 00:04:21,420
That is it the next video?

71
00:04:21,630 --> 00:04:25,130
Let's have a look at our next coding challenge.

