=counting valleys hacker rank code example
Example: the hiker first enters a valley 2 units deep
function countingValleys(n, s) { let level = 0; let result = 0; [...s].reduce((target, step) => { step.match(/u/i) ? level++ : level--; (!target && level >= 0) && (result++); target = !!(level >= 0); return target; }, true); return result;}