Here is my answer, which is wrong, but I cant figure out why. The logic seems fine but my acc
is returning a larger number than expected most of the time.
Here is the question:
The first input array contains the correct answers to an exam, like ["a", "a", "b", "d"]. The second one is "answers" array and contains student's answers.
The two arrays are not empty and are the same length. Return the score for this array of answers, giving +4 for each correct answer, -1 for each incorrect answer, and +0 for each blank answer(empty string).
My Answer:
function checkExam(array1, array2) {
return array1.concat(array2).reduce((acc, curr, i) =>
curr[i] === curr[i + array1.length] ? acc + 4 : curr[i + array1.length] === '' ? acc + 0 : acc - 1, 0);
}