Directions Reduction
DESCRIPTION
Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side).
The Haskell version takes a list of directions with data Direction = North | East | West | South.
The Clojure version returns nil when the path is reduced to nothing.
The Rust version takes a slice of enum Direction {North, East, West, South}.
详细描述可以查看文档底部的引用链接。
SOLUTION
- 方法一:模拟栈的方式。
1 | function dirReduc(arr) { |
- 方法二:正则表达式 +
while
循环。
1 | function dirReduc(arr) { |