Created
May 29, 2019 09:35
-
-
Save Oliver-ke/cc99c573694683fa979bd7431954bfa3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (answers, studentAns) => { | |
if (answers.length !== studentAns.length) { | |
return 'Arrays must be of the same length'; | |
} | |
let sum = 0; | |
for (let i = 0; i < answers.length; i++) { | |
if (answers[i] === studentAns[i]) { | |
sum += 4; | |
} else if (studentAns[i] !== ' ') { | |
sum -= 1; | |
} | |
} | |
sum = sum < 0 ? 0 : sum; | |
return sum; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A function that computes results given two arrays, an answer array, and a student answer array