Skip to content

[LIS-WDFT-APR2023] Elnaz #3738

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
Closed

Conversation

elnazfe
Copy link

@elnazfe elnazfe commented Apr 12, 2023

Iteration #8 πŸ€―πŸ€―πŸ€―πŸ€―πŸ˜΅πŸ˜΅πŸ˜΅β€πŸ’«πŸ˜΅β€πŸ’«πŸ˜΅β€πŸ’«

Copy link

@joaopdg joaopdg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job on the lab+bonus Elnaz!

if (mixedArr[i] === true) {
arrSum += 1;
}
arrAvg = arrSum/mixedArr.length
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line of code where you are calculating the average should be outside of any condition, otherwise if for some reason the array passed to the function doesn't have any boolean that line of code will never be read, so you can actually do this math operation in the return:

function avg(mixedArr) {
  if (mixedArr.length === 0) {
    return null;
  } 
  let arrSum = 0;
    for (let i = 0; i < mixedArr.length; i++) {
      if (typeof mixedArr[i] === 'number') {
        arrSum += mixedArr[i];
      } else if (typeof mixedArr[i] === 'string') {
        arrSum += mixedArr[i].length;
      } else if (typeof mixedArr[i] === 'boolean') {
        if (mixedArr[i] === true) {
          arrSum += 1;
        }
      }else{
        throw new Error("Invalid data type")
      }
    }
    return arrSum/mixedArr.length 
  }

Also, you're missing the last test which is to throw an error. For that you just need an else with the syntax for throwing an error inside. The jasmine test will continue to be red but your answer will be correct don't worry.

@stale
Copy link

stale bot commented May 21, 2023

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 May 21, 2023
@stale
Copy link

stale bot commented May 31, 2023

This pull request is closed. Thank you.

@stale stale bot closed this May 31, 2023
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