Last updated 4 years ago
Was this helpful?
input will gonna array1, and array2
reducing array1 for accumulate of compare result with array2
while iterate if array2[index] is same with array1[index] accumulate + 4, if not -1, butt if array2[index] is empty just do nothing
Returns the greater of 0 or process-1
const checkExam = (array1, array2) => Math.max( array1.reduce((acc, cur, i) => { if (cur === array2[i]) { return acc + 4; } if (!array2[i]) { return acc; } return acc - 1; }, 0), 0, );