Step 9

We can implement Luhn's algorithm in many different forms. Here, I will use the opportunity to explore array operations.

First, I will convert a card number (inputted as a string) to an array of characters.

const cnumber = "4003600000000014";

let arr = cnumber.split('');

console.log(arr);

The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The string is converted to an array of each of its characters when the separator is an empty string ('').

Since we work with the digits from right to left, we can use the array's reverse method to facilitate our goal.

const cnumber = "4003600000000014";

let arr = cnumber.split('');

arr = arr.reverse();

console.log(arr);