1
1
// Iteration #1: Find the maximum
2
2
3
+ function maxOfTwoNumbers ( a , b ) {
4
+ if ( a > b ) {
5
+ return a ;
6
+ } else {
7
+ return b ;
8
+ }
9
+ }
10
+
3
11
// Iteration #2: Find longest word
4
12
const words = [ 'mystery' , 'brother' , 'aviator' , 'crocodile' , 'pearl' , 'orchard' , 'crackpot' ] ;
5
13
14
+ function findLongestWord ( arr ) {
15
+ let longestWord = null ;
16
+ if ( arr . length > 0 ) {
17
+ let wordLength = 0 ;
18
+ for ( var i = 0 ; i < arr . length ; i ++ ) {
19
+ if ( arr [ i ] . length > wordLength ) {
20
+ wordLength = arr [ i ] . length ;
21
+ longestWord = arr [ i ] ;
22
+ }
23
+ }
24
+ }
25
+ return longestWord ;
26
+ }
27
+
28
+ findLongestWord ( words ) ;
29
+
30
+
6
31
// Iteration #3: Calculate the sum
7
32
8
33
const numbers = [ 6 , 12 , 1 , 18 , 13 , 16 , 2 , 1 , 8 , 10 ] ;
@@ -90,15 +115,4 @@ const matrix = [
90
115
[ 20 , 69 , 36 , 41 , 72 , 30 , 23 , 88 , 34 , 62 , 99 , 69 , 82 , 67 , 59 , 85 , 74 , 4 , 36 , 16 ] ,
91
116
[ 20 , 73 , 35 , 29 , 78 , 31 , 90 , 1 , 74 , 31 , 49 , 71 , 48 , 86 , 81 , 16 , 23 , 57 , 5 , 54 ] ,
92
117
[ 1 , 70 , 54 , 71 , 83 , 51 , 54 , 69 , 16 , 92 , 33 , 48 , 61 , 43 , 52 , 1 , 89 , 19 , 67 , 48 ]
93
- ] ;
94
-
95
-
96
- //Iteration #1: Find the maximum
97
-
98
- function maxOfTwoNumbers ( a , b ) {
99
- if ( a > b ) {
100
- return a ;
101
- } else {
102
- return b ;
103
- }
104
- }
118
+ ] ;
0 commit comments