-
Notifications
You must be signed in to change notification settings - Fork 6.7k
BER-FTWD-Phillip #1543
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
BER-FTWD-Phillip #1543
Conversation
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.
A really really well done lab!:) I decided to be a bit more strict in my comments as you are very advanced in javascript already, but this is soooo nicely coded!
@@ -1,19 +1,103 @@ | ||
// Iteration #1: Find the maximum | ||
|
||
function maxOfTwoNumbers(a,b){ | ||
if(a > b){ |
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 rather write: if(a >= b) {return a}
This way you dont need to make the else statement:)
// Iteration #2: Find longest word | ||
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; | ||
|
||
function findLongestWord(arr) { | ||
if(arr.length == 0){ | ||
return null; |
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.
Since you return here, you dont need to have an else statement as you are returning here (meaning it will go out of the function and not execute the rest of the function anyways)
let sum2 = 0; | ||
|
||
for(let j=0; j < mixArr.length; j++) { | ||
if(typeof mixArr[j] == "number") { |
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 actually make and or statement here:
typeof mixArr[j] == "number" || typeof mixArr[j] == "boolean"
since a number + a boolean results in: 5 + true === 6, and 5 + false === 5
return null; | ||
} | ||
|
||
return sumNumbers(numArr)/numArr.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.
Nice to see you are re-using your functions!
return null; | ||
} | ||
|
||
return Array.from(new Set(wordsArr)); |
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.
Clever;)
return null; | ||
} | ||
|
||
if(wordsArr.find(word => word == searchterm) !== 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.
I THINK you can instead write:
return wordsArr.find(word => word == searchterm) !== undefined
this will either return true or false depending if the condition is met or not
Thanks Markus,
your notes are much appreciated as they help me learn more effective!
Von: Markus Heldrup <notifications@github.com>
Gesendet: Mittwoch, 25. März 2020 12:07
An: ironhack-labs/lab-javascript-functions-and-arrays <lab-javascript-functions-and-arrays@noreply.github.com>
Cc: phpaul89 <phillippaul@gmx.de>; Author <author@noreply.github.com>
Betreff: Re: [ironhack-labs/lab-javascript-functions-and-arrays] BER-FTWD-Phillip (#1543)
@fenrew commented on this pull request.
A really really well done lab!:) I decided to be a bit more strict in my comments as you are very advanced in javascript already, but this is soooo nicely coded!
_____
In src/functions-and-arrays.js <#1543 (comment)> :
@@ -1,19 +1,103 @@
// Iteration #1: Find the maximum
+function maxOfTwoNumbers(a,b){
+ if(a > b){
You can rather write: if(a >= b) {return a}
This way you dont need to make the else statement:)
_____
In src/functions-and-arrays.js <#1543 (comment)> :
// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
+function findLongestWord(arr) {
+ if(arr.length == 0){
+ return null;
Since you return here, you dont need to have an else statement as you are returning here (meaning it will go out of the function and not execute the rest of the function anyways)
_____
In src/functions-and-arrays.js <#1543 (comment)> :
+ let sum1 = 0;
+
+ for(let i=0; i < arr.length; i++){
+ sum1 += arr[i];
+ }
+
+ return sum1;
+}
+
+const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
+
+function sum(mixArr){
+ let sum2 = 0;
+
+ for(let j=0; j < mixArr.length; j++) {
+ if(typeof mixArr[j] == "number") {
You can actually make and or statement here:
typeof mixArr[j] == "number" || typeof mixArr[j] == "boolean"
since a number + a boolean results in: 5 + true === 6, and 5 + false === 5
_____
In src/functions-and-arrays.js <#1543 (comment)> :
// Iteration #4: Calculate the average
// Level 1: Array of numbers
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
+function averageNumbers (numArr){
+ if(numArr.length == 0){
+ return null;
+ }
+
+ return sumNumbers(numArr)/numArr.length;
Nice to see you are re-using your functions!
_____
In src/functions-and-arrays.js <#1543 (comment)> :
@@ -29,9 +113,29 @@ const wordsUnique = [
'bring'
];
+function uniquifyArray (wordsArr){
+ if(wordsArr.length == 0){
+ return null;
+ }
+
+ return Array.from(new Set(wordsArr));
Clever;)
_____
In src/functions-and-arrays.js <#1543 (comment)> :
// Iteration #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
+function doesWordExist (wordsArr, searchterm){
+ if(wordsArr.length == 0){
+ return null;
+ }
+
+ if(wordsArr.find(word => word == searchterm) !== undefined){
I THINK you can instead write:
return wordsArr.find(word => word == searchterm) !== undefined
this will either return true or false depending if the condition is met or not
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#1543 (review)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AMUOMFLFER6LE5SUW4WPADDRJHQVRANCNFSM4LS4HS4Q> . <https://github.com/notifications/beacon/AMUOMFKAMGL2NZ5EJRPB3JTRJHQVRA5CNFSM4LS4HS42YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOC23DX5Y.gif>
|
This pull request has been automatically marked as stale because it didn't have any recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request is closed. Thank you. |
except Bonus Iteration 8 & 8.1