How to resolve the algorithm Split a character string based on change of character step by step in the jq programming language

Published on 12 May 2024 09:40 PM
#Jq

How to resolve the algorithm Split a character string based on change of character step by step in the jq programming language

Table of Contents

Problem Statement

Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below).

Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas.

For instance, the string: should be split and show:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Split a character string based on change of character step by step in the jq programming language

Source code in the jq programming language

# input: a string
# output: a stream of runs
def runs:
  def init:
    explode as $s
    | $s[0] as $i
    | (1 | until( $s[.] != $i; .+1));
  if length == 0 then empty
  elif length == 1 then .
  else init as $n | .[0:$n], (.[$n:] | runs)
  end;

"gHHH5YY++///\\" | [runs] | join(", ")

  

You may also check:How to resolve the algorithm Fractal tree step by step in the OCaml programming language
You may also check:How to resolve the algorithm Bitmap/Histogram step by step in the PHP programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the Retro programming language
You may also check:How to resolve the algorithm Nautical bell step by step in the Julia programming language
You may also check:How to resolve the algorithm Handle a signal step by step in the Raku programming language