Skip to content

JS 1 - #41

Closed
BonnW wants to merge 1 commit into
bloominstituteoftechnology:masterfrom
BonnW:master
Closed

JS 1 #41
BonnW wants to merge 1 commit into
bloominstituteoftechnology:masterfrom
BonnW:master

Conversation

@BonnW

@BonnW BonnW commented Oct 5, 2017

Copy link
Copy Markdown

No description provided.

Comment thread src/arrays.js
// `startingValue` is the starting value. If `startingValue` is undefined then make `elements[0]` the initial value.
let memo;
if (startingValue) {
memo = cb(startingValue, elements[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass elements to the cb in your for loop

Comment thread src/objects.js
const newArr = [];
Object.keys(obj).forEach((key, value) => {
newArr[value] = key;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.keys(obj) returns an array of all the keys as strings. You don't have to do anything else.

Comment thread src/objects.js
// http://underscorejs.org/#values
const newArr = [];
Object.keys(obj).forEach((key, value) => {
newArr[value] = obj[key];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may already be aware of this, but just to clarify: when you use .forEach((key, value)) what you're really passing to the function is the key and the index of the key in the Object.keys array. As is, this function is passing values to newArr, but it's because you're assigning the values with obj[key] at newArr[index]. obj[key] points to that key's value.

@sperrye sperrye left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed, great work

@sperrye sperrye closed this Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants