@@ -19,23 +19,38 @@ function findLongestWord(words) {
19
19
return words [ 0 ]
20
20
} else if ( words . length > 1 ) {
21
21
words . sort ( function ( a , b ) {
22
- if ( a . length < b . length ) return 1 ; // 1 here (instead of -1 for ASC)
23
- if ( a . length > b . length ) return - 1 ; // -1 here (instead of 1 for ASC)
22
+ if ( a . length < b . length ) return 1 ;
23
+ if ( a . length > b . length ) return - 1 ;
24
24
if ( a . length === b . length ) return 0 ;
25
25
} ) ;
26
26
}
27
27
return words [ 0 ]
28
28
}
29
29
30
30
// Iteration #3: Calculate the sum
31
- const numbers = [ 6 , 12 , 1 , 18 , 13 , 16 , 2 , 1 , 8 , 10 ] ;
32
-
33
- function sumNumbers ( ) { }
31
+ // const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
32
+
33
+ function sumNumbers ( numbers ) {
34
+ if ( numbers . length === 0 ) {
35
+ return 0
36
+ } else if ( numbers . length >= 1 ) {
37
+ let sum = 0
38
+ for ( let i = 0 ; i < numbers . length ; ++ i )
39
+ sum += numbers [ i ] ;
40
+ return sum
41
+ }
42
+ }
34
43
35
44
36
45
37
46
// Iteration #3.1 Bonus:
38
- function sum ( ) { }
47
+ // const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
48
+
49
+ function sum ( mixedArr ) {
50
+
51
+
52
+ }
53
+
39
54
40
55
41
56
0 commit comments