Given a two-dimensional array of integers and a string "N", "E", "S", "W", return the middle element along the border in the given compass direction, or the average of the two middle ones if the border length is even.