Created
October 9, 2015 21:41
-
-
Save aradnom/5049f186bbca8383f57c to your computer and use it in GitHub Desktop.
Splits passed credit number into quartets (groups of 4 digits).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Split a credit card into groups of four for more readable display. | |
* | |
* @param {Integer} number Number to split | |
* | |
* @return {String} Returns formatted number for display | |
*/ | |
function splitCardNumber ( number ) { | |
return number | |
.toString() | |
.split( '' ) | |
.reduce( function ( stack, next, index ) { | |
return ( index + 1 ) % 4 ? stack + next : stack + next + ' '; | |
}, '' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment