Multisplit: Difference between revisions
J: simpler
m (→{{header|Haskell}}: Tidied) |
(J: simpler) |
||
Line 819:
=={{header|J}}==
<lang j>multisplit=:
'
j=. k=. 0 NB. j indexes text, k indexes of (potential) instances of separators in text
while.
'b s'=. k{bs NB. unpack details about next separator
if. _=b do. r,.(j}.x);'' return. end. NB. finish if no more separators
txt=. (j + i. b-j){x NB. extract text between separators
j=. b+s{#@>y NB. advance to position after seprator
r=.r,.txt;s,b NB. update partial result
end.
▲)</lang>
Explanation:
First find all potentially relevant separator instances, and sort them in increasing order, by starting location and separator index. <code>sep</code> is separator index, and <code>begin</code> is starting
Then, loop through the possibilities, skipping over those separators which would overlap with previously used separators.
|