We are going to write a function called cardHide that will accept a string, card, as an argument.

You are given a string containing numbers that represent a credit card number. The goal of the function is to return the string with all of the numbers replaced by asterisks except for the last four digits. The string length must remain the same.

Examples:

cardHide("1234123456785678") // "************5678"
cardHide("8754456321113213") // "************3213"

In the example above you see that when the function returns the hidden credit card number it hides all the values with asterisks except for the last four digits.

To begin writing this in code, we are going to create an array called hideNum. This is the variable the function will return. Initially, it is an array but we are going to output it as a string.

let hideNum = [];

Next, we will use a for loop to loop through the string. Inside the loop, we replace the character with an asterisk until you reach the fourth to last digit or character in the string.

#web-development #algorithms #javascript

JavaScript Algorithm: Hiding the Card Number
3.05 GEEK