Untitled
Anonymous
javascript
01/11/2024 9:34 PM
492 B
21
Indexable
function isValidWalk(walk) {
const score = walk.reduce((acc, step) => {
if (step === 'n') acc.upDown += 1;
if (step === 's') acc.upDown -= 1;
if (step === 'e') acc.leftRight += 1;
if (step === 'w') acc.leftRight -= 1;
return acc
}, { upDown: 0, leftRight: 0 })
return score.upDown === 0 && score.leftRight === 0 && walk.length === 10
}Editor is loading...
Leave a Comment