Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@nomyard
Copy link

@nomyard nomyard commented Aug 8, 2017

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

const multiplyByTen = (num) => {
// return num after multiplying it by ten
// code here
return num * 10;
Copy link
Contributor

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) {
Copy link
Contributor

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;

Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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) {
Copy link
Contributor

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') {
Copy link
Contributor

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++) {
Copy link
Contributor

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];
Copy link
Contributor

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]}`;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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!'
Copy link
Contributor

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++) {
Copy link
Contributor

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;
Copy link
Contributor

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

@SunJieMing SunJieMing closed this Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.