-
Notifications
You must be signed in to change notification settings - Fork 137
Completed Projects w/ Matt Jackson #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| const multiplyByTen = (num) => { | ||
| // return num after multiplying it by ten | ||
| // code here | ||
| return num * 10; |
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 is fine but you can also simplify the whole function to look like this:
const multiplyByTen = (num) => num * 10;
The value is automatically returned.
| // return true if the two strings have the same length | ||
| // otherwise return false | ||
| // code here | ||
| if (str1.length === str2.length) { |
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.
Whenever you have an if statement for returning true or false you can usually simplify it to something like this:
return str1.length === str2.length;
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.
The expression is automatically simplified to either a true or a false
| // return true if x and y are the same | ||
| // otherwise return false | ||
| // code here | ||
| if (x === y) { |
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 here, just do return x === y;
| if (x === y) { | ||
| return true; | ||
| } | ||
| return false; |
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 whole function could be simplified to: const areEqual = (x, y) => x === y;
| const getBiggest = (x, y) => { | ||
| // x and y are integers. Return the larger integer | ||
| // if they are the same return either one | ||
| if (x > y) { |
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 usually like to simplify if statements like this to look a little different:
if (x > y) return x;
return y;
You could also use a ternary operator:
return x > y ? x : y;
Which would simplify to const getBiggest = (x, y) => x > y ? x : y;
| // language: 'Spanish' -> 'Hola!' | ||
| // language: 'Chinese' -> 'Ni Hao!' | ||
| // if language is undefined return 'Hello!' | ||
| if (language === 'German') { |
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.
Great, you could use a switch statement here too
| } else if (num === 0 || num === 1 || num % 2 === 0) { | ||
| return false; | ||
| } | ||
| for (let i = 3; i < num; 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 could also have this skip all even numbers: i += 2 instead of i++
| // return a string that is all of the words concatenated together | ||
| // spaces need to be between each word | ||
| // example: ['Hello', 'world!'] -> 'Hello world!' | ||
| let everyWord = words[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.
You can use reduce here.
| // example: ['Hello', 'world!'] -> 'Hello world!' | ||
| let everyWord = words[0]; | ||
| for (let i = 1; i < words.length; i++) { | ||
| everyWord += ` ${words[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 shouldn't need to wrap words[i] in the template literal. Just do +=. Maybe the linter was barking at you though
| const addNumbers = (numbers) => { | ||
| // numbers is an array of integers. | ||
| // add all of the integers and return the value | ||
| let sum = 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.
This is also a great time to use Array.reduce. It's fine that you didn't but now that you're becoming more advanced this is where you should use it
| const largestNumber = (numbers) => { | ||
| // numbers is an array of integers | ||
| // return the largest integer | ||
| let largest = 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.
You could use reduce or forEach here.
| return { | ||
| name, | ||
| age, | ||
| meow: () => 'Meow!' |
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
| // each user object has the property 'isPremium' | ||
| // set each user's isPremium property to true | ||
| // return the users array | ||
| for (let i = 0; i < users.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.
forEach would be good here
| // each post object has an integer property called 'likes' | ||
| // sum together the likes from all the post objects | ||
| // return the sum | ||
| let sum = 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.
reduce is good for stuff like this
We passed all projects- but there is a disparity with project 2. At one point during the push and pulling of the projects something got jumbled up. There may be a rogue project file that we can't identify at this point- kind of confusing to be honest.
It runs all 4 projects at 100% on our machines.
If someone can point us to what we may have done wrong that would be great.
Raymond Rosario and Matt Jackson