Skip to main content
1 of 4
George Reith
  • 2.5k
  • 1
  • 14
  • 16

#Javascript (ES6), 64 bytes

a=>a.reduce((p,c)=>p+c.match(/(.+?)\s+#/)[1].slice(p.length),'')

Takes input as an array of strings.

F=a=>a.reduce((p,c)=>p+c.match(/(.+?)\s+#/)[1].slice(p.length),'')

input.oninput = update;
update();

function update() {
  try {
    output.innerHTML = F(input.value.trim().split`
`);
  } catch(e) {
    output.innerHTML = 'ERROR: INVALID INPUT';
  }
}
textarea {
  width: 100%;
  box-sizing: border-box;
}
<h2>Input:</h2>
<textarea id="input" rows="8">
a                #Explanation of what 'a' does
 bc              #Bc
   d             #d
    e            #Explanation of e
     fgh         #foobar
        ij       #hello world
          k      #etc.
           l     #so on
            mn   #and
              op #so forth
</textarea>
<hr />
<h2>Output:</h2>
<div id="output">
</div>

George Reith
  • 2.5k
  • 1
  • 14
  • 16