Remove indentation

0

Write a program which removes any common leading spaces from the input string. For example, if the least indented line started with 3 spaces, and every other line has >= 3 leading spaces, then remove 3 spaces from the beginning of each line.

The indentation consists solely of spaces, and the string will not contain any tabulation. This is the same as the textwrap.dedent function in python.

Example (input, output):

Input

       7aeiou
   3b
     555

Output

    7aeiou
3b
  555

Input

this
 is
  a
   test

Output

this
 is
  a
   test

Input

    Hello 
 world

Output

   Hello 
world

Mathieu CAROFF

Posted 2019-01-03T21:17:31.610

Reputation: 109

Question was closed 2019-01-03T22:56:56.947

2Hi! I'm not familiar with Python. Can you explain what the dedent function does, so we can replicate it without needing to know Python? Thanks! – AdmBorkBork – 2019-01-03T21:24:54.723

1please don't override PPCG's default submission guidelines. It's usually perfectly fine to submit functions without calling them, and allowing input as a predefined variable just turns submissions into snippets – Jo King – 2019-01-03T21:25:59.577

3

Additionally, this looks very close to being a duplicate of https://codegolf.stackexchange.com/q/53219/42963

– AdmBorkBork – 2019-01-03T21:26:05.997

It seems that example text looses 3 leading spaces on each line? Is this what the task is? May we assume that input always has at least 3 spaces on each line? May we assume a variable to hold a list of strings if this is more natural to our language? – Adám – 2019-01-03T21:27:07.703

@DJMcMayhem, thanks, I didn't know what the minimum proper question could be. – Mathieu CAROFF – 2019-01-03T22:22:06.833

Answers

0

Perl 6, 11 bytes

*.indent(*)

Try it online!

Jo King

Posted 2019-01-03T21:17:31.610

Reputation: 38 234