- Notifications
You must be signed in to change notification settings - Fork6.7k
BER_FT_03_23_23_HeimLi#3683
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
if (num1 > num2) { return num1 } | ||
else { return num2 } | ||
} | ||
result = maxOfTwoNumbers(3, 5); |
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 don't need to call your function here to make it work. If you use it, to test your code, that's fine! 😉 But you should better remove these function calls before you submit the lab.
//console.log(typeof (wordLength)); | ||
for (let i = 0; i < words.length; i++) { | ||
if (wordLength.length < words[i].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.
Better store the longest word in a string, not an array and just compare the length by using longestWord.length
return averageNumbersSum/2 | ||
} | ||
let result4 = averageNumbers(numbersAvg); |
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 should divide the total sum by the amount of numbers in the array to get the average
for (let i = 0; i < wordsUnique.length; i++) { | ||
if (newArray.includes(wordsUnique[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 check if the array doesn't include the word by using!newArray.includes(wordsUnique[i])
, then you don't need an else
for (let i = 0; i < wordsFind.length; i++) { | ||
if (wordsFind.includes(givenWord)) { | ||
console.log("true"); break |
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.
Good solution, you just need to replace the console.log with a return-statement
howManyTimes, | ||
greatestProduct | ||
}; | ||
} |
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.
Good solutions! ✨ Keep on the good work!
Danke!:)Marco Lölkes ***@***.***> schrieb am Di. 28. März 2023 um17:52: … ***@***.**** commented on this pull request. ------------------------------ In src/functions-and-arrays.js <#3683 (comment)> : > @@ -1,41 +1,96 @@ // Iteration#1: Find the maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(num1, num2) { + if (num1 > num2) { return num1 } + else { return num2 } +} +result = maxOfTwoNumbers(3, 5); You don't need to call your function here to make it work. If you use it, to test your code, that's fine! 😉 But you should better remove these function calls before you submit the lab. ------------------------------ In src/functions-and-arrays.js <#3683 (comment)> : > // Iteration#2: Find longest word + +function findLongestWord(words) { + + let wordLength = []; + wordLength.push(words[0]); + //console.log(wordLength); + //console.log(typeof (wordLength)); + + for (let i = 0; i < words.length; i++) { + if (wordLength.length < words[i].length) { Better store the longest word in a string, not an array and just compare the length by using longestWord.length ------------------------------ In src/functions-and-arrays.js <#3683 (comment)> : > // Iteration#4: Calculate the average // Level 1: Array of numbers const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; -function averageNumbers() {} +function averageNumbers(numbersAvg) { + let averageNumbersSum = 0; + + for (let i = 0; i < numbersAvg.length; i++) { + averageNumbersSum = averageNumbersSum + numbersAvg[i] + } + return averageNumbersSum/2 +} + +let result4 = averageNumbers(numbersAvg); You should divide the total sum by the amount of numbers in the array to get the average ------------------------------ In src/functions-and-arrays.js <#3683 (comment)> : > @@ -52,15 +107,37 @@ const wordsUnique = [ 'bring' ]; -function uniquifyArray() {} +function uniquifyArray(wordsUnique) { + + let newArray = []; + + for (let i = 0; i < wordsUnique.length; i++) { + + if (newArray.includes(wordsUnique[i])) { You could also check if the array doesn't include the word by using !newArray.includes(wordsUnique[i]), then you don't need an else ------------------------------ In src/functions-and-arrays.js <#3683 (comment)> : > + for (let i = 0; i < wordsFind.length; i++) { + if (wordsFind.includes(givenWord)) { + console.log("true"); break Good solution, you just need to replace the console.log with a return-statement ------------------------------ In src/functions-and-arrays.js <#3683 (comment)> : > - }; -} + module.exports = { + maxOfTwoNumbers, + findLongestWord, + sumNumbers, + sum, + averageNumbers, + averageWordLength, + avg, + uniquifyArray, + doesWordExist, + howManyTimes, + greatestProduct + }; + } Good solutions! ✨ Keep on the good work! — Reply to this email directly, view it on GitHub <#3683 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A6NA4S5LEMY3EDYZ6VUNCZ3W6MCM5ANCNFSM6AAAAAAWFPJWO4> . You are receiving this because you authored the thread.Message ID: <ironhack-labs/lab-javascript-functions-and-arrays/pull/3683/review/1361318361 @github.com> |
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. |
No description provided.