mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
✨ Add "maskify-card-number" challenge
This commit is contained in:
parent
3d4aa20915
commit
dd075269f2
13
challenges/maskify-card-number/README.md
Normal file
13
challenges/maskify-card-number/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# maskify-card-number
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) at 5 July 2020.
|
||||
|
||||
## Instructions :
|
||||
|
||||
Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.
|
||||
|
||||
Your task is to write a function, which changes all but the last four characters into `'#'`.
|
||||
|
||||
## Examples :
|
||||
|
||||
See the `input-output.json` file for examples of input/output.
|
14
challenges/maskify-card-number/input-output.json
Normal file
14
challenges/maskify-card-number/input-output.json
Normal file
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"input": ["4556364607935616"],
|
||||
"output": "############5616"
|
||||
},
|
||||
{
|
||||
"input": ["1"],
|
||||
"output": "1"
|
||||
},
|
||||
{
|
||||
"input": ["11111"],
|
||||
"output": "#1111"
|
||||
}
|
||||
]
|
0
challenges/maskify-card-number/solutions/.gitkeep
Normal file
0
challenges/maskify-card-number/solutions/.gitkeep
Normal file
@ -0,0 +1,4 @@
|
||||
# typescript-maskify - maskify-card-number
|
||||
|
||||
Programming language : TypeScript
|
||||
Created by [@Divlo](https://github.com/Divlo) at 5 July 2020.
|
@ -0,0 +1,11 @@
|
||||
function solution (string: string) {
|
||||
return string
|
||||
.split('')
|
||||
.map((character, index) => {
|
||||
if (string.length - 4 > index) return '#'
|
||||
return character
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
|
||||
export default solution
|
Loading…
Reference in New Issue
Block a user