Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. function countingValleys(n, s) {
  2. let result = 0;
  3. const arr = s.split("")
  4. .map(v => (v === 'U') ? 1 : -1)
  5. .reduce((a, c) => {
  6. if (a + c === 0 && a < 0) result += 1;
  7. return a + c;
  8. }, 0);
  9. return result;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement