Skip to content

Instantly share code, notes, and snippets.

@moreirayokoyama
Created March 8, 2012 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moreirayokoyama/2002607 to your computer and use it in GitHub Desktop.
Save moreirayokoyama/2002607 to your computer and use it in GitHub Desktop.
Mod 10 (declarative fashion)
function mod10(numbers) {
var multipliers = [2, 1];
var multiplicands = numbers.reverse();
var products = mapProducts(multiplicands, multipliers);
var mod = products.map(
function (number) {
return number.toString().split('').map(
function (str) {
return parseInt(str);
}).sum();
}).sum() % 10;
if (mod >= 10) return 0;
return 10 - mod;
}
@juanplopes
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment