-
Notifications
You must be signed in to change notification settings - Fork 100
Solutions for Advanced-JavaScript #55
Solutions for Advanced-JavaScript #55
Conversation
ryan-hamblin
left a comment
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.
Overall things are looking pretty good. I would suggest coming back and plowing through the extra credit. Also there are many line breaks where there don't need to be, and as for me, (this being a stylistic preference) I would return the PR and ask you to fix those line breaks. But that's not the case for everyone's style. Overall you're doing great. Keep it up. Keep plowing through the complicated stuff! It's not easy!
| // declare result array object to be returned. | ||
| const result = []; | ||
| // loop over the elements | ||
| for (let i = 0; i < elements.length; i++) { |
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.
You're good to reuse your .each() method here. Maybe you could give it a try.
| }; | ||
| let result = []; | ||
|
|
||
| function getValues(element, res = []) { |
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.
Nice default in the parens.
| return res; | ||
| } | ||
|
|
||
| for (let i = 0; i < elements.length; i++) { |
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.
Not sure what's going on with two different loops here. There may be a better way to solve this. Please refer to the video posted about flatten and reduce, it's up in Week 1 on your piazza account.
| // `meow` that should return the string `<name> meowed!` where `<name>` is the `name` | ||
| // property set on the Cat instance. | ||
|
|
||
| class User { |
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.
This all looks really good. It seems like you have a good grasp on these concepts here.
|
|
||
| return (...val) => { | ||
| count++; | ||
|
|
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.
No need for this space right here.
| const result = []; | ||
| return (unknown) => { | ||
| if (arg.indexOf(unknown) !== -1) { | ||
| return result[arg.indexOf(unknown)]; |
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.
Nice work. I really like indexOf. And I like that you used an array to cache your function call. I would rename this array to something more descriptive other than 'arg' just to make sure if someone was to re-read your code, they'd be able to understand exactly what 'arg' is.
| return result.push(obj[k]); | ||
| }); | ||
|
|
||
| // for (const key in obj) { |
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.
You can just deleted code that you've commented out. It makes for a cleaner submission.
| // Return `obj`. | ||
| // http://underscorejs.org/#defaults | ||
| function hasKey(o, ky) { | ||
| // const objKeys = Object.keys(o); |
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.
please remove this commented out code
| const nFibonacci = (n) => { | ||
| // fibonacci sequence: 1 2 3 5 8 13 ... | ||
| // return the nth number in the sequence | ||
| if (n < 0) { |
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.
I think you can simplify all of this logic to one single line. if (n <= 2) return n
| }); | ||
| // console.log(`Check: No object found in values. (@ depth level:${level})`); | ||
| return true; | ||
| // ~~~~~~~~WHYYY!!!!!! Does this happen!!!!!!~~~~~ |
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.
You're going to be receiving this as a toy problem today. You should be able to think through it. Otherwise you'll have some exposure to it and you'll be able to come back and nail it!
First set of complete answers.