Skip to content

Commit 880fbef

Browse files
Víctor Heras ÁlvarezVíctor Heras Álvarez
authored andcommitted
done
1 parent c4f4d5a commit 880fbef

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed

starter-code/src/functions-and-arrays.js

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,78 @@
1-
// Find the maximum
1+
function maxOfTwoNumbers (numero1, numero2){
2+
if (numero1 > numero2)
3+
return numero1;
4+
else return numero2;
5+
}// Find the maximum
26

37
// Finding Longest Word
4-
var words = [
5-
'mystery',
6-
'brother',
7-
'aviator',
8-
'crocodile',
9-
'pearl',
10-
'orchard',
11-
'crackpot'
12-
];
138

14-
// Calculating a Sum
9+
var words = ['mystery','brother','aviator','crocodile','pearl','orchard','crackpot'];
10+
11+
function findLongestWord(words){
12+
if (words.length==0) return;
13+
var max = " ";
14+
words.forEach (function(name){
15+
if (name.length>max.length){
16+
max = name;
17+
};
18+
});
19+
return max
20+
};
21+
22+
console.log (findLongestWord (words));
1523

24+
25+
26+
// Calculating a Sum
1627
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
28+
function sumArray (numbers){
29+
var suma = 0;
30+
numbers.forEach (function(number){
31+
suma = suma + number;
32+
})
33+
return suma;
34+
}
1735

1836
// Calculate the Average
1937

20-
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
38+
var numbers= [2, 6, 9, 10, 7, 4, 1, 9];
39+
function averageNumbers (numbers){
40+
if (numbers.length==0) return;
41+
var suma = 0;
42+
numbers.forEach (function(number){
43+
suma = suma + number;
44+
})
45+
return suma / numbers.length;
46+
}
47+
2148

2249
// Array of Strings
23-
var wordsArr = [
24-
'seat',
25-
'correspond',
26-
'linen',
27-
'motif',
28-
'hole',
29-
'smell',
30-
'smart',
31-
'chaos',
32-
'fuel',
33-
'palace'
50+
var wordsArr = ['seat','correspond','linen','motif','hole','smell','smart','chaos','fuel','palace'
3451
];
52+
function averageWordLength (wordsArr){
53+
if (wordsArr.length==0) return;
54+
var suma = 0;
55+
wordsArr.forEach (function(word){
56+
suma = suma + word.length;
57+
})
58+
return suma / wordsArr.length;
59+
}
3560

3661
// Unique Arrays
37-
var wordsUnique = [
38-
'crab',
39-
'poison',
40-
'contagious',
41-
'simple',
42-
'bring',
43-
'sharp',
44-
'playground',
45-
'poison',
46-
'communion',
47-
'simple',
48-
'bring'
62+
var wordsUnique = ['crab','poison','contagious','simple','bring','sharp','playground','poison','communion','simple',
63+
'bring'
4964
];
5065

66+
//function uniquifyArray (wordsUnique){
67+
if (wordsUnique.indexOf("");
68+
}
69+
70+
})
71+
}
72+
73+
74+
75+
5176
// Finding Elements
5277
var wordsFind = [
5378
'machine',

0 commit comments

Comments
 (0)