Skip to content

Commit 1049e66

Browse files
committed
Finished arrays, but filter still not passing all tests.
1 parent f4f9f1c commit 1049e66

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/arrays.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const each = (elements, cb) => {
1414
// This only needs to work with arrays.
1515
// You should also pass the index into `cb` as the second argument
1616
// based off http://underscorejs.org/#each
17-
for (let i = 0; i <= elements.length; i++) {
17+
for (let i = 0; i <= elements.length - 1; i++) {
1818
cb(elements[i], i);
1919
}
2020
};
@@ -59,12 +59,24 @@ const find = (elements, cb) => {
5959
// Look through each value in `elements` and pass each element to `cb`.
6060
// If `cb` returns `true` then return that element.
6161
// Return `undefined` if no elements pass the truth test.
62+
for (let i = 0; i < elements.length; i++) {
63+
if (cb(elements[i]) === true) {
64+
return elements[i];
65+
}
66+
}
6267
};
6368

6469
const filter = (elements, cb) => {
6570
// Do NOT use .filter, to complete this function.
6671
// Similar to `find` but you will return an array of all elements that passed the truth test
6772
// Return an empty array if no elements pass the truth test
73+
const filtrue = [];
74+
for (let i = 0; i < elements.length; i++) {
75+
if (cb(elements[i]) === true) {
76+
return filtrue.push(elements[i]);
77+
}
78+
return filtrue;
79+
}
6880
};
6981

7082
/* STRETCH PROBLEM */

yarn-error.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Arguments:
2-
/usr/local/bin/node /usr/local/Cellar/yarn/1.5.1_1/libexec/bin/yarn.js test objects.test.js
2+
/usr/local/bin/node /usr/local/Cellar/yarn/1.5.1_1/libexec/bin/yarn.js test arrays.test.js
33

44
PATH:
55
/Users/ericandrade/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
@@ -3592,7 +3592,7 @@ Trace:
35923592
Error: Command failed.
35933593
Exit code: 1
35943594
Command: sh
3595-
Arguments: -c eslint tests/*.js && eslint src/*.js && jest --verbose objects.test.js
3595+
Arguments: -c eslint tests/*.js && eslint src/*.js && jest --verbose arrays.test.js
35963596
Directory: /Users/ericandrade/Desktop/JavaScript-I
35973597
Output:
35983598

0 commit comments

Comments
 (0)