- Notifications
You must be signed in to change notification settings - Fork6.7k
[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 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
joaopdg left a comment
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.
Awesome job on the lab+bonus Elnaz!
if (mixedArr[i] === true) { | ||
arrSum += 1; | ||
} | ||
arrAvg = arrSum/mixedArr.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.
This line of code where you arecalculating the average should beoutside of any condition, otherwise if for some reason the array passed to the function doesn't have anyboolean that line of code will never be read, so you can actually do this math operation in thereturn:
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.
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. |
Iteration#8 🤯🤯🤯🤯😵😵😵💫😵💫😵💫