-
Notifications
You must be signed in to change notification settings - Fork 100
Advanced JS #22
Advanced JS #22
Conversation
| // 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'; |
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.
Actually return undefined and not the string 'undefined'
| if (Array.isArray(elements[i])) { | ||
| arr = arr.concat(flatten(elements[i])); | ||
| } else arr.push(elements[i]); | ||
| } return arr; |
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.
Put the return on the next line
| } | ||
|
|
||
| comparePasswords(myPassword) { | ||
| if (this.password === myPassword) return true; |
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.
Just do return this.password === myPassword; . It's automatically converted into a bool
| // use `this` to access the object's `password` property. | ||
| // do not modify this function's parameters | ||
| // note that we use the `function` keyword and not `=>` | ||
| if (passwordToCompare == this.password) { |
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.
Same thing: return passwordToCompare === this.password;. Make sure to use === over ==
| // return `true` if they match, otherwise return `false` | ||
|
|
||
| checkPassword(string) { | ||
| if (string === this.password) { |
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.
Same as below
Hey, haven't been able to finish this project just yet. Could you show us best practice solutions that we could compare / learn from?
Thanks in advance!