Advanced-JavaScript Completed - #39
Conversation
…ng stuff being put into the array. Passed a index into sevel arrays.js methods cause I forgot to do that before.
ryan-hamblin
left a comment
There was a problem hiding this comment.
Well done. I'm really stoked about how far along you are. There are a lot of advanced concepts that you grasp really well. I only had a few critiques.
| this.name = name; | ||
| this.hitpoints = hitpoints; | ||
| this.level = level; | ||
| this.inventory = inventory || []; |
There was a problem hiding this comment.
You could potentially just default this in the constructor parens. constructor(inventory = [])
which would allow you to forego the ||.
| @@ -0,0 +1,135 @@ | |||
| /** | |||
There was a problem hiding this comment.
This is really really fun! I'd like to rephrase something though. Objects in Javascript don't necessarily "Inherit" they way that you may be used to from other OO Languages. It's more that a "Parent" class would be "Delegating" do it's "Sub-classes". I'm sure you're aware of these intricacies, but I wanted to make it very clear Here is a link to a great article that talks about Prototypal 'inheritance' which really should say prototypal 'delegation'
| // Combine all elements into a single value going from left to right. | ||
| // Elements will be passed one by one into `cb`. | ||
| // `memo` is the starting value. If `memo` is undefined then make `elements[0]` the initial value. | ||
| if (typeof memo === 'undefined') { |
There was a problem hiding this comment.
This would be unnecessary as you have defaulted already in the function parens
| // Example: flatten([1, [2], [3, [[4]]]]); => [1, 2, 3, 4]; | ||
| const array = []; | ||
| const cb = (item) => { | ||
| if (item instanceof Array) { |
There was a problem hiding this comment.
nice, instance of is great, you should look into Array.isArray()
| // `cb` should only ever be invoked once for a given set of arguments. | ||
| const cache = {}; | ||
| return (arg) => { | ||
| if (!(arg in cache)) { |
| // Based on http://underscorejs.org/#keys | ||
|
|
||
| // not sure how to do this without just using an Object method | ||
| return arrayMethods.reduce(Object.entries(obj), (array, [key, value]) => { |
There was a problem hiding this comment.
functional and shows you understand the concepts of the methods you've created already! Nice work!
| // Like map for arrays, but for objects. Transform the value of each property in turn. | ||
| // http://underscorejs.org/#mapObject | ||
| const newObj = {}; | ||
| for (let i = 0; i < keys(obj).length; i++) { |
There was a problem hiding this comment.
Awesome. Passing your object back to your very one 'key' function. This is good stuff.
No description provided.