mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(challenges): add left-pad
This commit is contained in:
parent
b92b834458
commit
47de82f417
35
challenges/left-pad/README.md
Normal file
35
challenges/left-pad/README.md
Normal file
@ -0,0 +1,35 @@
|
||||
# left-pad
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 21 May 2023.
|
||||
|
||||
## Instructions
|
||||
|
||||
Create a function that pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string.
|
||||
|
||||
Inspired from [left-pad (JavaScript npm package)](https://www.npmjs.com/package/left-pad).
|
||||
|
||||
### Input
|
||||
|
||||
- **Line 1:** The current string
|
||||
- **Line 2:** The length of the resulting string
|
||||
- **Line 3:** The string to pad the current string with
|
||||
|
||||
## Examples
|
||||
|
||||
See the `test` folder for examples of input/output.
|
||||
|
||||
### Example 1
|
||||
|
||||
#### Input
|
||||
|
||||
```txt
|
||||
foo
|
||||
12
|
||||
-
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```txt
|
||||
---------foo
|
||||
```
|
0
challenges/left-pad/solutions/.gitkeep
Normal file
0
challenges/left-pad/solutions/.gitkeep
Normal file
3
challenges/left-pad/test/1/input.txt
Normal file
3
challenges/left-pad/test/1/input.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foo
|
||||
12
|
||||
-
|
1
challenges/left-pad/test/1/output.txt
Normal file
1
challenges/left-pad/test/1/output.txt
Normal file
@ -0,0 +1 @@
|
||||
---------foo
|
3
challenges/left-pad/test/2/input.txt
Normal file
3
challenges/left-pad/test/2/input.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foobar
|
||||
5
|
||||
|
1
challenges/left-pad/test/2/output.txt
Normal file
1
challenges/left-pad/test/2/output.txt
Normal file
@ -0,0 +1 @@
|
||||
foobar
|
3
challenges/left-pad/test/3/input.txt
Normal file
3
challenges/left-pad/test/3/input.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foo
|
||||
4
|
||||
|
1
challenges/left-pad/test/3/output.txt
Normal file
1
challenges/left-pad/test/3/output.txt
Normal file
@ -0,0 +1 @@
|
||||
foo
|
3
challenges/left-pad/test/4/input.txt
Normal file
3
challenges/left-pad/test/4/input.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foo
|
||||
5
|
||||
|
1
challenges/left-pad/test/4/output.txt
Normal file
1
challenges/left-pad/test/4/output.txt
Normal file
@ -0,0 +1 @@
|
||||
foo
|
3
challenges/left-pad/test/5/input.txt
Normal file
3
challenges/left-pad/test/5/input.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foobar
|
||||
13
|
||||
|
1
challenges/left-pad/test/5/output.txt
Normal file
1
challenges/left-pad/test/5/output.txt
Normal file
@ -0,0 +1 @@
|
||||
foobar
|
3
challenges/left-pad/test/6/input.txt
Normal file
3
challenges/left-pad/test/6/input.txt
Normal file
@ -0,0 +1,3 @@
|
||||
foobar
|
||||
6
|
||||
|
1
challenges/left-pad/test/6/output.txt
Normal file
1
challenges/left-pad/test/6/output.txt
Normal file
@ -0,0 +1 @@
|
||||
foobar
|
Loading…
Reference in New Issue
Block a user