В
function countingValleys(steps, path) {
return [...path].reduce((acc, step) => {
if (acc.stack.length === 0) {
acc[step]++
acc.stack.push(step)
return acc
}
if (acc.stack.pop() === step) {
acc.stack.push(step, step)
}
return acc
}, { stack: [], U: 0, D: 0 }).D
}



