Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

nellyneumann
Copy link

I had a problem with the exercise #7 - Count repetition.
I couldn't resolve it.

Copy link

@ahmedhany82 ahmedhany82 left a 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];

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.

Comment on lines +49 to +52
let sum = sumNumbers (numbersarray)
let numberOfElements= numbersarray.length
let average = sum / numberOfElements
return average

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

Comment on lines +58 to +65
function averageWordLength(wordsarray) {
let wordlist = []
for (let i = 0; i < wordsarray.length; i++){
wordlist.push(wordsarray[i].length)
}
let average = averageNumbers(wordlist)
return average
}

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;
}

Comment on lines +92 to +103
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
}

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.

Comment on lines +85 to +87
function uniquifyArray(wordsUniqueArray) {

}

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.

@stale
Copy link

stale bot commented Jul 8, 2021

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.

@stale stale bot added the stale label Jul 8, 2021
@stale
Copy link

stale bot commented Jul 10, 2021

This pull request is closed. Thank you.

@stale stale bot closed this Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants