-
Notifications
You must be signed in to change notification settings - Fork 264
JS-I&II Push 1 #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
JS-I&II Push 1 #299
Changes from 1 commit
3f20c0c
64ac9c8
5d0f761
7cbcb08
c7d9ba4
7a6f473
5f7204c
ac6fdec
12f6c43
5551e4d
335d554
8e18a1a
1abe623
31b6ef9
24af335
05715f9
af193aa
e6c7c92
8fcec1e
52fb8df
2feb65c
2b932c9
562b033
d07f981
66e6665
d0c2428
1368e2a
596ac7a
64a1d1a
0eb2079
35a3e9c
b736828
1e4bd03
8b67e55
9474129
1f11634
2042266
8431210
62f362b
dc1da47
30b3bda
5508f10
5f0a836
ba0f29a
40f98bd
eefb0be
95aeb7a
39f89f0
062ef52
ca7edf1
2bf1668
63943d4
af37541
6b9f397
ae42472
af5963b
d926cc8
ed3a5eb
a99bb2c
4f31478
1f151d1
09ba0eb
991b887
944cf23
a4f4485
20e45cc
db614cf
f8bb8f5
0733587
2e06ff0
7e42716
895296b
4d8ef58
4e2a0be
51f8fc1
7dd5187
07c2874
1d2c2ba
9d8a490
9ac6e65
cb51a92
d465365
d9e0e21
3063d8b
f855cc6
eb7dd64
b3af50e
5a3ba70
c6990bc
0dd77c5
18e7f00
c0cf386
04f21c9
a7a9330
018be3d
cd5d9a6
8d275b4
fdf9a22
f1f2bb0
e0cfdf2
6ccb06e
7f59eaf
6d09c88
ff44f23
350129d
0fefc09
3110982
3e3e6c6
31658bf
20f45e6
8b343f3
c95ce83
b0297a2
b22bacc
4da6caf
ad686e6
d32e97d
b59d1df
e610ac9
bad20a7
aba4299
e46e99a
00edcc5
d07f6d3
1ba4583
427e1b6
ef0b09a
58cae01
466302e
a3c768a
efcdac8
9480e26
37d234b
d2bb122
87ff57e
82c5981
09d94b8
4052579
60572c0
79861c7
b0a40a1
7f28a68
7325c46
bdc1b86
2632a75
20f83b7
7e06b72
3ca6440
bbae680
aab1b9c
382a7a3
5dcb88a
a4718d3
2d89367
1f1f453
e7e8e0f
755d3cb
328def3
9f5f6e2
35fdef8
199d144
6f3bd2d
58c2e8d
0bc468d
84eb171
924ac7f
a0dd388
8e866d0
e2dc7e7
86b4dbe
f2b3b75
8ec6ea1
160e961
3a3144a
e56d68a
d9b9b01
4583359
81e49bc
ac22c62
876be8c
4eb2194
dbbd75c
13386a8
4703f23
31249d4
7a1fb3a
75b6be3
325ff45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,33 +14,63 @@ const each = (elements, cb) => { | |
| // This only needs to work with arrays. | ||
| // You should also pass the index into `cb` as the second argument | ||
| // based off http://underscorejs.org/#each | ||
|
|
||
| for (let i = 0; i < elements.length; i++) { | ||
| cb(elements[i], i); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| const map = (elements, cb) => { | ||
| // Do NOT use .map, to complete this function. | ||
| // Produces a new array of values by mapping each value in list through a transformation function (iteratee). | ||
| // Return the new array. | ||
| const myMap = []; | ||
| for (let i = 0; i < elements.length; i++) { | ||
| myMap.push(cb(elements[i])); | ||
| } | ||
| return myMap; | ||
| }; | ||
|
|
||
|
|
||
| const reduce = (elements, cb, startingValue) => { | ||
| // Do NOT use .reduce, to complete this function. | ||
| // Combine all elements into a single value going from left to right. | ||
| // Elements will be passed one by one into `cb` along with the `startingValue`. | ||
| // `startingValue` should be the first argument passed to `cb` and the array element should be the second argument. | ||
| // `startingValue` is the starting value. If `startingValue` is undefined then make `elements[0]` the initial value. | ||
| if (startingValue === undefined) { | ||
| startingValue = elements[0]; | ||
| } | ||
| for (let i = startingValue; i < elements.length; i++) { | ||
| startingValue = cb(startingValue, elements[i]); | ||
| } | ||
| return startingValue; | ||
| }; | ||
|
|
||
| const find = (elements, cb) => { | ||
| // Do NOT use .includes, to complete this function. | ||
| // Look through each value in `elements` and pass each element to `cb`. | ||
| // If `cb` returns `true` then return that element. | ||
| // Return `undefined` if no elements pass the truth test. | ||
| for (let i = 0; i < elements.length; i++) { | ||
| if (cb(elements[i]) === true) { | ||
| return elements[i]; | ||
| } | ||
| } return undefined; | ||
| }; | ||
|
|
||
|
|
||
| const filter = (elements, cb) => { | ||
| // Do NOT use .filter, to complete this function. | ||
| // Similar to `find` but you will return an array of all elements that passed the truth test | ||
| // Return an empty array if no elements pass the truth test | ||
| const newFilter = []; | ||
| for (let i = 0; i < elements.length; i++) { | ||
| if (cb(elements[i]) === true) { | ||
| newFilter.push(elements[i]); | ||
| } | ||
| } return newFilter; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is fine, it's generally suggested that you separate these. It gets hard to debug if you've forgotten something small in this scenario. |
||
| }; | ||
|
|
||
| /* STRETCH PROBLEM */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,17 +5,24 @@ const keys = (obj) => { | |
| // Retrieve all the names of the object's properties. | ||
| // Return the keys as strings in an array. | ||
| // Based on http://underscorejs.org/#keys | ||
| return Object.keys(obj); | ||
| }; | ||
|
|
||
| const values = (obj) => { | ||
| // Return all of the values of the object's own properties. | ||
| // Ignore functions | ||
| // http://underscorejs.org/#values | ||
| return Object.values(obj); | ||
| }; | ||
|
|
||
| const mapObject = (obj, cb) => { | ||
| // Like map for arrays, but for objects. Transform the value of each property in turn. | ||
| // http://underscorejs.org/#mapObject | ||
| const myMap = {}; | ||
| for (let i = 0; i < obj.length; i++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you could add a property of |
||
| myMap.push(obj[i]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't push into an object. |
||
| } | ||
| cb(myMap); | ||
| }; | ||
|
|
||
| const pairs = (obj) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was pairs forgotten about? |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting value can be anything a
number,string,objectattempting to seti(theindex) to starting value is nonsensical. We went over this briefly last night whereishould be dynamic dependent on ifstartingValueis undefined.