JavaScript Algorithm: Hiding the Card Number

JavaScript Algorithm: Hiding the Card Number

Write a function that will display only the last four digits of a credit card number.

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Top Web Development Company in India

We are the best offshore web development company in India providing web applications on Blockchain, AI & Chatbots. 15+ Yrs Exp., Save upto 60% on development.

Web Design and Development Services

Get Best out from Web Design and Development Services from Vinew Technologies,We have a dedicated team of experienced and knowledgeable web developers, designers and testers. Therefore, we have proficiency in analyzing, developing and designing the necessity of intricate Website Development projects.

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.