Basic-Javascript Proj1-4#6
Conversation
taithethai
left a comment
There was a problem hiding this comment.
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;
| @@ -3,137 +3,165 @@ | |||
| const multiplyByTen = (num) => { | |||
There was a problem hiding this comment.
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 num * 10; | ||
| }; | ||
|
|
||
| const subtractFive = (num) => { |
| return num - 5; | ||
| }; | ||
|
|
||
| const areSameLength = (str1, str2) => { |
There was a problem hiding this comment.
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
| return Math.ceil(num); | ||
| }; | ||
|
|
||
| const addExclamationPoint = (str) => { |
There was a problem hiding this comment.
Good use of Template Literals.
| @@ -3,6 +3,8 @@ | |||
| const getBiggest = (x, y) => { | |||
There was a problem hiding this comment.
Good.
You could also convert this to a ternary statement.
| return y; | ||
| }; | ||
|
|
||
| const greeting = (language) => { |
There was a problem hiding this comment.
You can drop English if your base case and English are the same. You could also consider making use of switch cases.
| return arr[0]; | ||
| }; | ||
|
|
||
| const returnLast = (arr) => { |
There was a problem hiding this comment.
Here, you're mutating your array.
You'll want to be using arr[arr.length - 1].
| return arr.length; | ||
| }; | ||
|
|
||
| const incrementByOne = (arr) => { |
There was a problem hiding this comment.
You could merge line 89 and 90.
arr[i] += 1;
| return numbers.reduce(sum); | ||
| }; | ||
|
|
||
| const averageTestScore = (testScores) => { |
There was a problem hiding this comment.
Good use of reduce. You could also just put the contents of line 135 inside the reduce.
| const cat = { | ||
| name, | ||
| age, | ||
| meow() { |
There was a problem hiding this comment.
You could use arrow function, and have it in one line.
from Satish Vattikuti/Sandeep Chandran