Skip to main content
1 of 3
NinjaBearMonkey
  • 10.4k
  • 3
  • 37
  • 66

JavaScript ES6, 83 bytes

f=(z,a=[])=>z.replace(/ *0/g,e=>e.replace('0',a.fill(0,l=e.length)[--l]=a[l]+1||1))

This uses an array that holds the current number for each indentation level. Everything past that level is reset to 0 using fill().

NinjaBearMonkey
  • 10.4k
  • 3
  • 37
  • 66