Skip to content

Commit e4a47c3

Browse files
committed
almost done- will have time to complete tomorrow
1 parent 2fe12b3 commit e4a47c3

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Ohne Titel.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"folders": [],
3+
"settings": {}
4+
}

starter-code/.DS_Store

0 Bytes
Binary file not shown.

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ function maxOfTwoNumbers (nb1, nb2) {
44
if (nb1 > nb2) {return nb1;} else if (nb1 < nb2) {return nb2;} else {return nb1}
55
}
66

7-
8-
97
// Finding Longest Word
108
var words = [
119
'mystery',
@@ -28,6 +26,9 @@ function findLongestWord(array) {
2826

2927
findLongestWord(words);
3028

29+
// alternative solution witch forEach.function()
30+
31+
3132
// Calculating a Sum
3233

3334
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
@@ -43,6 +44,7 @@ return sum;
4344
}
4445

4546
// Calculate the Average
47+
// re-use sum function
4648

4749
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
4850

@@ -78,7 +80,7 @@ return sumWords/array.length
7880

7981
averageWordLength(wordsArr)
8082

81-
// Unique Arrays
83+
// Unique Arrays - please don't tell me the solution yet - will work on it tomorrow :)
8284
var wordsUnique = [
8385
'crab',
8486
'poison',
@@ -104,7 +106,7 @@ for (var i = 0; i < array.length; i++) {
104106
if (array[i] === array[j]) {array.splice(array[i],1)}
105107
else {continue;}
106108

107-
}
109+
}
108110

109111
}
110112

@@ -122,6 +124,12 @@ var wordsFind = [
122124
'disobedience'
123125
];
124126

127+
function doesWordExist(array, word) {
128+
for(var i = 0; i < array.length; i++) {
129+
if(array[i] === word) {return true;}
130+
} return false;
131+
}
132+
125133
// Counting Repetion
126134
var wordsCount = [
127135
'machine',
@@ -136,7 +144,18 @@ var wordsCount = [
136144
'disobedience',
137145
'matter'
138146
];
139-
// Bonus Quest
147+
148+
function howManyTimes(array, word) {
149+
var counter = 0;
150+
if(array.length === 0) {return false};
151+
152+
for(var i = 0; i < array.length; i++) {
153+
if(array[i] === word) {counter += 1}
154+
} return counter;}
155+
156+
157+
158+
// Bonus Quest - will as well do tomorrow
140159

141160
var matrix = [
142161
[8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],

0 commit comments

Comments
 (0)