-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcardHide.js
More file actions
21 lines (17 loc) · 729 Bytes
/
cardHide.js
File metadata and controls
21 lines (17 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Write a function that takes a credit card number and only displays the last four characters.
// The rest of the card number must be replaced by ************.
// Examples:
// cardHide("1234123456785678") ➞ "************5678"
// cardHide("8754456321113213") ➞ "************3213"
// cardHide("35123413355523") ➞ "**********5523"
// Notes:
// Ensure you return a string.
// The length of the string must remain the same as the input.
function cardHide(card) {
const fullNumber = card;
const last4Digits = fullNumber.slice(-4);
return last4Digits.padStart(fullNumber.length, "*");
}
console.log(cardHide("1234123456785678"));
// Solution 2:
// const cardHide = card => '*'.repeat(card.length - 4) + card.slice(-4);