Skip to content

Basic-Javascript Proj1-4#6

Closed
deepsun80 wants to merge 4 commits into
bloominstituteoftechnology:masterfrom
deepsun80:master
Closed

Basic-Javascript Proj1-4#6
deepsun80 wants to merge 4 commits into
bloominstituteoftechnology:masterfrom
deepsun80:master

Conversation

@deepsun80

Copy link
Copy Markdown

from Satish Vattikuti/Sandeep Chandran

@taithethai taithethai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a lot of these, you could convert them into one line, and you could be returning the contents of the if statement. I.E.
const areEqual = (x, y) => return x === y;

Comment thread src/project-1.js
@@ -3,137 +3,165 @@
const multiplyByTen = (num) => {

Copy link
Copy Markdown
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.

Comment thread src/project-1.js
return num * 10;
};

const subtractFive = (num) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Comment thread src/project-1.js
return num - 5;
};

const areSameLength = (str1, str2) => {

Copy link
Copy Markdown
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;
The expression is automatically simplified to either a true or a false

Comment thread src/project-1.js
return Math.ceil(num);
};

const addExclamationPoint = (str) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of Template Literals.

Comment thread src/project-2.js
@@ -3,6 +3,8 @@
const getBiggest = (x, y) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

You could also convert this to a ternary statement.

Comment thread src/project-2.js
return y;
};

const greeting = (language) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop English if your base case and English are the same. You could also consider making use of switch cases.

Comment thread src/project-2.js
return arr[0];
};

const returnLast = (arr) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you're mutating your array.
You'll want to be using arr[arr.length - 1].

Comment thread src/project-2.js
return arr.length;
};

const incrementByOne = (arr) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could merge line 89 and 90.
arr[i] += 1;

Comment thread src/project-2.js
return numbers.reduce(sum);
};

const averageTestScore = (testScores) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of reduce. You could also just put the contents of line 135 inside the reduce.

Comment thread src/project-3.js
const cat = {
name,
age,
meow() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use arrow function, and have it in one line.

@taithethai taithethai closed this Aug 20, 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