-
Notifications
You must be signed in to change notification settings - Fork 6.7k
BER-WDFT-052021-Nelly Neumann -Solved Lab #2406
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
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.
Hey Nelly,
Good job with the lab. I added a few comments below. I see you mentioned that you had a problem with the count repetition but it looks fine to me. Perhaps you meant unique array ? Let me know if you have any specific questions. If you have some time, give the bonus a try ;)
Best regards,
Ahmed
function sumNumbers(numbersarray) { | ||
let result = 0; | ||
for (let i = 0; i < numbersarray.length; i++) { | ||
result = result + numbersarray[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 write this as result += numbersarray[i];
but this is just a tiny detail.
let sum = sumNumbers (numbersarray) | ||
let numberOfElements= numbersarray.length | ||
let average = sum / numberOfElements | ||
return average |
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.
Another tiny detail. Just so that you know, you could do this in one line return sumNumbers(numbersarray) / numbersarray.length
function averageWordLength(wordsarray) { | ||
let wordlist = [] | ||
for (let i = 0; i < wordsarray.length; i++){ | ||
wordlist.push(wordsarray[i].length) | ||
} | ||
let average = averageNumbers(wordlist) | ||
return average | ||
} |
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.
This works fine but it creates an extra array. Since the length is just a number we can add all the lengths in a variable instead. But the way you did it also works.
function averageWordLength(words) {
if (words.length === 0) return null;
let sum = 0;
for (let i=0; i < words.length; i++) {
sum += words[i].length;
}
return sum / words.length;
}
function doesWordExist(wordsFindArray,word) { | ||
if (wordsFindArray.length === 0) { | ||
return null; | ||
} | ||
let found = false | ||
for (let i = 0; i < wordsFindArray.length; i++){ | ||
if (wordsFindArray [i] === word){ | ||
found = true | ||
} | ||
} | ||
return found | ||
} |
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.
This works but if the target word is the first word in the array and the array has 1000 elements, it will still loop on the entire array before returning true. Instead you could directly return true in line 99 so the function ends and return true as soon as the target is found. If the for loop is finished, then this means the target was not found and you can return false.
function uniquifyArray(wordsUniqueArray) { | ||
|
||
} |
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.
Check the lab solution for this one and feel free to reach out if you have any questions.
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. |
I had a problem with the exercise #7 - Count repetition.
I couldn't resolve it.