advanced javascript hw - #17
Conversation
| } | ||
| let total = memo; // 10 | ||
| for (; i < elements.length; i++) { | ||
| total += elements[i]; |
There was a problem hiding this comment.
You wouldn't want to use += here. That is doing addition or string concatenation. You would want to actually overwrite the memo. memo = cb(memo, elements[i]);
| // 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])) { // tai says look at this |
There was a problem hiding this comment.
This works fine. Because cb is returning true or false it will pass or fail the if statement
| // for a potential password that will be compared to the `password` property. | ||
| // Return true if the potential password matches the `password` property. Otherwise return false. | ||
|
|
||
| class User { |
There was a problem hiding this comment.
This may have had something to do with the file but the indentation is different here than it was in the previous file. I recommend a tab of 2 spaces. The main point though is to pick one style and stay consistent with it throughout your project.
| this.age = options.age; | ||
| } | ||
| growOlder() { | ||
| return this.age++; |
There was a problem hiding this comment.
Something funny to be aware of here is that the ++ postfix operator will apply the incrementation AFTER the value has been returned. So if you have 1 and you go return 1++; a 1 is returned and then it is turned into a 2.
|
|
||
| const counter = () => { | ||
| let count = 0; | ||
| return () => ++count; |
There was a problem hiding this comment.
So here you're using ++ as a prefix operator which increments the value BEFORE returning it. Kind of a funny difference that trips people up from time to time.
| const counterFactory = () => { | ||
| let count = 0 | ||
| return { | ||
| increment: () => (++count), |
There was a problem hiding this comment.
Good job using the shorthand syntax
| return { | ||
| increment: () => (++count), | ||
| decrement: () => (--count) | ||
| } |
There was a problem hiding this comment.
You're missing a ; here
| const food = 'pineapple'; | ||
|
|
||
| var isMyFavoriteFood = function(food) { | ||
| const isMyFavoriteFood = (food) =>{ |
There was a problem hiding this comment.
Put a space after the =>
| } | ||
| class User { | ||
| constructor(options) { | ||
| this.username = options.username |
There was a problem hiding this comment.
Make sure everything inside of the constructor method is indented
| } | ||
| sayHi () { | ||
| return `${username} says hello!`; | ||
| }; |
There was a problem hiding this comment.
A class also does not need a ; at the end. You are also missing a closing } after the sayHi method
|
|
||
| var argsToCb = function (cb) { | ||
| var args = Array.prototype.slice.call(arguments); | ||
| const argsToCb = (cb) { |
| const values = (obj) => { | ||
| return Object.keys(obj).map((key) => { | ||
| return obj; | ||
| }) |
There was a problem hiding this comment.
You're missing a ; here
| // Complete the following functions. | ||
|
|
||
| const nFibonacci = (n) => { | ||
| if (n <= 1) { |
There was a problem hiding this comment.
Same thing with indendation
|
|
||
| const nFibonacci = (n) => { | ||
| if (n <= 1) { | ||
| return 1 |
| if (n <= 1) { | ||
| return 1 | ||
| } | ||
| return n * nFibonacci(n-1); |
There was a problem hiding this comment.
Put space around your - so: n - 1
| }; | ||
|
|
||
| const nFactorial = (n) => { | ||
| if (n <= 1) { |
There was a problem hiding this comment.
With the factorial you would need to return 1 as the base case.
if (n <= 1) return 1;
return n * nFactorial(n - 1);
| }; | ||
|
|
||
| const checkMatchingLeaves = (obj) => { | ||
| if (obj.property) { |
There was a problem hiding this comment.
I know you don't have a finished solution here but it's always good to mind the indentation, even with incomplete code.
| // set a username and password property on the user object that is created | ||
| } | ||
| checkPassword(passwordToCompare) { | ||
| if (this.password === passwordToCompare) { |
There was a problem hiding this comment.
This can be simplified to return this.password === passwordToCompare;
The === means that the expression will be evaluated into true or false before it is returned
No description provided.