Skip to content

Commit 1f22b37

Browse files
Iteration ironhack-labs#6: Find elements completed
1 parent 8e127f0 commit 1f22b37

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/functions-and-arrays.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ const uniquifyArray = (arr) => {
152152
// Iteration #6: Find elements
153153
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
154154

155+
const doesWordExist = (arr, word) => {
156+
if ( arr.length === 0) {
157+
return null
158+
} else {
159+
return arr.includes(word)
160+
}
161+
}
162+
155163
// Iteration #7: Count repetition
156164
const wordsCount = [
157165
'machine',

tests/functions-and-arrays.spec.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,27 @@ describe('Unique array', () => {
205205
});
206206
});
207207

208-
// describe('Find elements', () => {
209-
// it('should create a function named doesWordExist', () => {
210-
// expect(typeof doesWordExist).toBe('function');
211-
// });
208+
describe('Find elements', () => {
209+
it('should create a function named doesWordExist', () => {
210+
expect(typeof doesWordExist).toBe('function');
211+
});
212212

213-
// it('should return null if receives an empty array when called', () => {
214-
// expect(doesWordExist([])).toBe(null);
215-
// });
213+
it('should return null if receives an empty array when called', () => {
214+
expect(doesWordExist([])).toBe(null);
215+
});
216216

217-
// it('should return true if the word we are looking for is the only one in the array', () => {
218-
// expect(doesWordExist(['machine'], 'machine')).toBe(true);
219-
// });
217+
it('should return true if the word we are looking for is the only one in the array', () => {
218+
expect(doesWordExist(['machine'], 'machine')).toBe(true);
219+
});
220220

221-
// it('should return false if the word we are looking for is not in the array', () => {
222-
// expect(doesWordExist(['machine', 'poison', 'eat', 'apple', 'horse'], 'ratatouille')).toBe(false);
223-
// });
221+
it('should return false if the word we are looking for is not in the array', () => {
222+
expect(doesWordExist(['machine', 'poison', 'eat', 'apple', 'horse'], 'ratatouille')).toBe(false);
223+
});
224224

225-
// it('should return true if the word we are looking for is in the array', () => {
226-
// expect(doesWordExist(['pizza', 'sandwich', 'snack', 'soda', 'book', 'computer'], 'book')).toBe(true);
227-
// });
228-
// });
225+
it('should return true if the word we are looking for is in the array', () => {
226+
expect(doesWordExist(['pizza', 'sandwich', 'snack', 'soda', 'book', 'computer'], 'book')).toBe(true);
227+
});
228+
});
229229

230230
// describe('Count repetition', () => {
231231
// it('should create a function named howManyTimes', () => {

0 commit comments

Comments
 (0)