14 assert.stringEqual is ===, see https://github.com/substack/tape

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) >=== "left-padded string"



This is , so the submission with the smallest number of bytes wins!

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) > "left-padded string"



This is , so the submission with the smallest number of bytes wins!

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) === "left-padded string"



This is , so the submission with the smallest number of bytes wins!

Post Reopened by Dennis
13 added 4 characters in body

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length of the stringnumber is greater or equal toor greater than the length of the string. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) > "left-padded string"



This is , so the submission with the smallest number of bytes wins!

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length of the string is greater or equal to the length. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) > "left-padded string"



This is , so the submission with the smallest number of bytes wins!

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) > "left-padded string"



This is , so the submission with the smallest number of bytes wins!

12 added 865 characters in body; edited title

### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad string onthis string in the left with enough copiesuntil the length of padstring that the full string reacheshas reached the length given in the function. In this case 6. Since the padchar is padlengthnot given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and then remove any excess chars from the left sideinitial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


Test casesWe just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the (first 4 fromstring, length, and maybe the additional argument original left-pad test suite):padchar, output the left-padded string. You can assume that the length of the string is greater or equal to the length. The padchar will always consist of 1 character.

### Test cases

fleft_pad('foo'"string", 5)length, ===("padchar")) '> "left-padded foo';string"
f


MayThis is , so the shortest answer winsubmission with the smallest number of bytes wins!

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

Your code should take 3 inputs: string, padlength, and padstring. If padstring doesn't exist, it defaults to a space. The task is to pad string on the left with enough copies of padstring that the string reaches length padlength, and then remove any excess chars from the left side.

Test cases (first 4 from the original left-pad test suite):

f('foo', 5) === '  foo';
f('foobar', 6) === 'foobar';
f(1, 2, 0) === '01';
f(1, 2, '-') === '-1';
f('a', 4, 'ab') === 'baba';


### Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

left_pad("abc", 6)


First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

   abc


This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

left_pad("abc", 6, "-")


We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

---abc


Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length of the string is greater or equal to the length. The padchar will always consist of 1 character.

### Test cases

left_pad("string", length, ("padchar")) > "left-padded string"



This is , so the submission with the smallest number of bytes wins!

Post Closed as "unclear what you're asking" by Dennis
11 added 89 characters in body
Post Reopened by Qwertiy, CalculatorFeline, edc65, Adnan, jrich
10 new test case with multichar padding