Jump to content

Split a character string based on change of character: Difference between revisions

jq
(Added ZX Spectrum BASIC)
(jq)
Line 601:
{{Out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
 
=={{header|jq}}==
<lang jq>def splitAtChange(sep):
explode
| if length==0 then []
else .[0] as $first
| reduce .[1:][] as $x ([[$first]];
if $x == .[-1][0] then .[-1] += [$x] else . + [[$x]] end)
end
| map(implode)
| join(sep) ;
 
"aabbcc" | splitAtChange(", ")</lang>
{{out}}
<pre>"aa, bb, cc"</pre>
 
 
=={{header|Kotlin}}==
2,526

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.