Sort an outline at every level: Difference between revisions

J draft
m (→‎{{header|Phix}}: added without js)
(J draft)
Line 769:
 
-> Inconsistent indent depths: [4,3,8,9,8,4,4,4,4]</pre>
 
=={{header|J}}==
Implementation:<lang J>parse2=: {{
((=<./)y (1 i.~ -.@e.)S:0 m) m {{
({.y),<m parse2^:(*@#)}.y
}};.1 y
}}
 
parseout=: {{
ws=. ' ',TAB
lines=: <;.2 y
indents=: lines (1 i.~ -.@e.)S:0 ws
unit=: +./indents
if. -. (-: i.@#)~.indents%unit do.
echo 'inconsistent indent widths'
end.
if. 1~:#~.;indents unit{{<(1,:m) <;._3 x{.;y }}"0 lines do.
echo 'inconsistent use of whitespace characters'
end.
ws parse2 lines
}} :.unparse
 
sortout=: {{ if. L.y do. u~ ({."1 y),.u sortout each}."1 y else. u~y end. }}
 
unparse=: {{ ;<S:0 y }}</lang>
 
Task examples (task data defined below):<lang J> /:sortout&.parseout sample1
alpha
epsilon
iota
theta
zeta
beta
delta
gamma
kappa
lambda
mu
 
\:sortout&.parseout sample1
zeta
gamma
mu
lambda
kappa
delta
beta
alpha
theta
iota
epsilon
 
/:sortout&.parseout sample2
alpha
epsilon
iota
theta
zeta
beta
delta
gamma
kappa
lambda
mu
 
/:sortout&.parseout sample3
inconsistent indent widths
inconsistent use of whitespace characters
alpha
iota
theta
zeta
beta
delta
gamma
kappa
lambda
mu
 
/:sortout&.parseout sample4
inconsistent indent widths
alpha
epsilon
iota
theta
zeta
gamma
delta
</lang>
 
Data for task examples:
<lang J>sample1=: {{)n
zeta
beta
gamma
lambda
kappa
mu
delta
alpha
theta
iota
epsilon
}}
 
 
sample2=:{{)n
zeta
gamma
mu
lambda
kappa
delta
beta
alpha
theta
iota
epsilon
}}
 
sample3=:{{)n
alpha
epsilon
iota
theta
zeta
beta
delta
gamma
kappa
lambda
mu
}}
 
sample4=:{{)n
zeta
beta
gamma
lambda
kappa
mu
delta
alpha
theta
iota
epsilon
}}</lang>
 
=={{header|Julia}}==
6,951

edits