Skip to content

Commit ffed54e

Browse files
committed
first six iterations
1 parent 543f1ae commit ffed54e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/functions-and-arrays.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,33 @@ const wordsUnique = [
8989
'bring'
9090
];
9191

92+
function uniquifyArray(arr) {
93+
let newArr = []
94+
if (arr.length === 0 ) {
95+
return null
96+
}
97+
for (let i = 0; i < arr.length; i++) {
98+
if (i === arr.indexOf(arr[i])) {
99+
newArr.push(arr[i])
100+
}
101+
}
102+
return newArr
103+
}
92104

93105
// Iteration #6: Find elements
94106
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
95107

108+
function doesWordExist (arr, word) {
109+
if (arr.length === 0)
110+
return null
111+
if (arr.includes(word)) {
112+
return true
113+
} else {
114+
return false
115+
}
116+
}
117+
118+
96119
// Iteration #7: Count repetition
97120
const wordsCount = [
98121
'machine',
@@ -132,3 +155,30 @@ const matrix = [
132155
[20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54],
133156
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
134157
];
158+
159+
// BONUS #1
160+
function sum () {
161+
162+
}
163+
164+
// BONUS #2
165+
// const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
166+
167+
// function avg (arr) {
168+
// if (arr.length ===0) {
169+
// return null
170+
// }
171+
// let resultString = 0
172+
// let resultNumber = 0
173+
// for (let i = 0; i < arr.length; i++) {
174+
// if (typeof arr[i] == "string") {
175+
// resultString += arr[i].length
176+
// } else if (typeof arr[i] == "number") {
177+
// resultNumber += arr[i]
178+
// } else if (typeof arr[i] == true) {
179+
// resultBoolean += 1
180+
// }
181+
// let average = resultString + resultNumber + resultBoolean/ arr.length
182+
183+
// return average
184+
// }

0 commit comments

Comments
 (0)