Skip to content

Commit 6efb366

Browse files
committed
segundaparte
1 parent b08e29b commit 6efb366

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

starter-code/functions-and-arrays.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,19 @@ console.log(average);
7373

7474
// Array of Strings
7575
function averageWordLength (array) {
76+
var total= 0;
77+
var media;
78+
for (var i = 0; i < array.length; i++) {
79+
total += array[i].length;
7680

81+
}
82+
media = total / array.length;
83+
return media;
7784
}
7885

86+
87+
88+
7989
var words = [
8090
"seat",
8191
"correspond",
@@ -92,10 +102,22 @@ var averageLength = averageWordLength(words);
92102
console.log(averageLength);
93103

94104
// Unique Arrays
105+
// indexOf devuelve -1 si no encuentra y position o indice de 1
95106
function uniquifyArray (array) {
107+
var nuevoArray = [];
96108

109+
for (i=0; i<array.length; i++){
110+
if(nuevoArray.indexOf(array[i],0) === -1){
111+
console.log("Introducimos el elemento");
112+
nuevoArray.push(array[i]);
113+
}
114+
}
115+
console.log(nuevoArray);
97116
}
98117

118+
119+
120+
99121
var words = [
100122
"crab",
101123
"poison",
@@ -108,10 +130,10 @@ var words = [
108130
"communion",
109131
"simple",
110132
"bring"
111-
];
112-
var uniqued = uniquifyArray(words);
133+
];var uniqued = uniquifyArray(words);
113134
console.log(uniqued);
114135

136+
115137
// Finding Elements
116138
function doesWordExist (wordsArray, word) {
117139

0 commit comments

Comments
 (0)