File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff 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
6469const 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 */
Original file line number Diff line number Diff line change 11Arguments:
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
44PATH:
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
You can’t perform that action at this time.
0 commit comments