Skip to content

Instantly share code, notes, and snippets.

@vlas-ilya
Created October 9, 2015 15:22
Show Gist options
  • Save vlas-ilya/c73880a4993f78ce1d9e to your computer and use it in GitHub Desktop.
Save vlas-ilya/c73880a4993f78ce1d9e to your computer and use it in GitHub Desktop.
var isValidCreditCard = function (xs) {
return xs.split('').reverse().map(function (elem, index, xs) {
return index % 2 ? (2 * elem < 9 ? 2 * elem : 2 * elem - 9) : Number(elem);
}).reduce(function(sum, elem) { return sum + elem }) % 10 == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment