Skip to content

Commit f1efc99

Browse files
done bonus exercises for iterations ironhack-labs#3, 4
1 parent 0aa8d96 commit f1efc99

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package-lock.json
55
yarn.lock
66
*.log
77
lab-solution.html
8+
src/functions-and-arrays-copy.js

src/functions-and-arrays-copy.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/functions-and-arrays.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,27 @@ function sumNumbers(someArray) {
4444

4545

4646
// Iteration #3.1 Bonus:
47-
function sum() {}
47+
// calculates the sum for array filled with (almost) any type of data
48+
function sum(someArray) {
49+
let sum = 0;
50+
//1. booleans: add 1 or 0 -> true + true = 2, so we good
51+
//2. string: add length
52+
//3. integers: add value
53+
if (someArray.length === 0) {
54+
return null;
55+
} else {
56+
for (let i = 0; i < someArray.length; i++) {
57+
if (typeof someArray[i] === "string" || typeof someArray[i] === "boolean") {
58+
sum += someArray[i].length;
59+
} else if (typeof someArray[i] === "number"){
60+
sum += someArray[i];
61+
}
62+
}
63+
}
64+
return sum;
65+
}
66+
67+
4868

4969

5070

@@ -82,7 +102,11 @@ function averageWordLength(wordsArr) {
82102
}
83103

84104
// Bonus - Iteration #4.1
85-
function avg() {}
105+
//calc avg of array filled w numbers, strings, booleans
106+
function avg(someArray) {
107+
let avg = sum(someArray)/someArray.length;
108+
return avg;
109+
}
86110

87111
// Iteration #5: Unique arrays
88112
const wordsUnique = [
@@ -185,7 +209,30 @@ const matrix = [
185209
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
186210
];
187211

188-
function greatestProduct() {}
212+
213+
//find the greates product of 4 adjacent number
214+
215+
function greatestProduct(someMatrix) {
216+
//create empty variable to store values
217+
//get the product of n1 n2 n3 n4, store it.
218+
//get the product of n2 n3 n4 n5, compare it with what's in the variable.
219+
//if second product is larger, replace it.
220+
//so on, for rows
221+
let greatestProduct = "";
222+
let productOfFour = "";
223+
let n1 = someMatrix.length[i][j];
224+
let n2 = someMatrix.length[i][j+1];
225+
let n3 = someMatrix.length[i][j+2];
226+
let n4 = someMatrix.length[i][j+3];
227+
for (i = 0; i > someMatrix.length; i++) {
228+
for (j = 0; j > someMatrix.length[j]; j++) {
229+
productOfFour = j*
230+
}
231+
}
232+
233+
}
234+
235+
//
189236

190237

191238

0 commit comments

Comments
 (0)