f=:((#~ 1&|.) ,&.> <;.1~) 0 1, 0= 2+/\ }: (<+_1*>) }. The first part assigns _1 to elements that are greater than the next one, and 1 to elements that are less than the next one. Where _1 1 or 1 _1 occur, a new group starts. Thus 0= 2+/\.
This gets us the starting indices for <;.1. Because the borders should be included, we prepend each element that is before a group start `(#~ 1&|.)` to that group `,&.>` (thus the unusual `0 1,` for the group starts). ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm