function checkTest(param1, param2) {
const reducer = (a, b, index) => {
if (b === '') {
return a
}
if (b === param1[index]) {
return (a += 4)
}
return --a
}
const score = param2.reduce(reducer, 0)
return score < 0 ? 0 : score
}
function checkTest2(param1, param2) {
let scope = 0
for (let i = 0; i < param1.length; i++) {
if (param1[i] === param2[i]) {
scope += 4
} else if (param2[i] === '') {
scope += 0
} else {
scope--
}
}
return scope < 0 ? 0 : scope
}
console.log(checkTest([1, 5, 8, 3, 2], [1, 3, 8, 3, '']))
console.log(checkTest2([1, 5, 8, 3, 2], [1, 3, 8, 3, '']))