T
Size: a a a
T
T
T
F
Е
З🧟
T
З🧟
T
function countingValleys(steps, path) {
let p = Array.from(path).reduce((res, el) => {
let last = res[res.length - 1];
res.push(last + (el === 'D' ? -1 : 1))
return res;
}, [0])
const res = p.filter((el, idx, arr) => (
idx !== arr.length - 1 && (el === 0 && arr[idx + 1] === -1)
))
return res.length
}F
F
p
F
T
function countingValleys(steps, path) {
return Array.from(path).reduce((res, el) => ([...res, res[res.length - 1] + (el === 'D' ? -1 : 1)]), [0]).filter((el, idx, arr) => (idx !== arr.length - 1 && (el === 0 && arr[idx + 1] === -1))).length
}F
T
T
function countingValleys(steps, path) {
return Array.from(path).reduce((res, el) => (res.push(res[res.length - 1] + (el === 'D' ? -1 : 1)), res), [0]).filter((el, idx, arr) => (idx !== arr.length - 1 && (el === 0 && arr[idx + 1] === -1))).length
}
а так успеваетDE
new Array(length).fill() на порядок быстрее чем фромT