Skip to content

Commit 78add35

Browse files
committed
iteration ironhack-labs#6
1 parent 24837ac commit 78add35

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/functions-and-arrays.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard',
1414

1515
function findLongestWord(arrOfWords) {
1616

17-
if (!arrOfWords.length) {
18-
return null;
19-
}
17+
if (!arrOfWords.length) return null;
2018

2119
let longestWord = '';
2220

@@ -37,7 +35,7 @@ const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
3735

3836
function sumNumbers(arrOfNums) {
3937

40-
if (arrOfNums.length === 0) return 0;
38+
if (!arrOfNums.length) return 0;
4139

4240
let sum = 0;
4341

@@ -64,7 +62,7 @@ const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
6462

6563
function averageNumbers(arrOfNums) {
6664

67-
if (arrOfNums.length === 0) return null;
65+
if (!arrOfNums.length) return null;
6866

6967
const length = arrOfNums.length;
7068
let avg;
@@ -82,7 +80,7 @@ const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smar
8280

8381
function averageWordLength(arrOfWords) {
8482

85-
if (arrOfWords.length === 0) return null;
83+
if (!arrOfWords.length) return null;
8684

8785
const length = arrOfWords.length;
8886
let sum = 0;
@@ -121,7 +119,7 @@ const wordsUnique = [
121119

122120
function uniquifyArray(arrOfWords) {
123121

124-
if (arrOfWords.length === 0) return null;
122+
if (!arrOfWords.length) return null;
125123

126124
let uniqeArray = [];
127125
let wordCounter = 1;
@@ -133,15 +131,25 @@ function uniquifyArray(arrOfWords) {
133131
});
134132

135133
return uniqeArray.length === arrOfWords ? arrOfWords : uniqeArray;
136-
134+
137135
}
138136

139137

140138

141139
// Iteration #6: Find elements
142140
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
143141

144-
function doesWordExist() {}
142+
function doesWordExist(arrOfWords, wordToSearch) {
143+
144+
if (!arrOfWords.length) return null;
145+
146+
if (arrOfWords.length === 1 && arrOfWords.includes(wordToSearch)) {
147+
return true;
148+
}
149+
150+
return arrOfWords.includes(wordToSearch) ? true : false;
151+
152+
}
145153

146154

147155

0 commit comments

Comments
 (0)