Skip to content

Instantly share code, notes, and snippets.

@Oliver-ke
Created May 29, 2019 09:35
Show Gist options
  • Save Oliver-ke/cc99c573694683fa979bd7431954bfa3 to your computer and use it in GitHub Desktop.
Save Oliver-ke/cc99c573694683fa979bd7431954bfa3 to your computer and use it in GitHub Desktop.
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;
};
@Oliver-ke
Copy link
Author

A function that computes results given two arrays, an answer array, and a student answer array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment