Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Forked from moreirayokoyama/gist:2002607
Created March 8, 2012 20:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save juanplopes/2003306 to your computer and use it in GitHub Desktop.
Mod 10 (declarative fashion)
function mod10(numbers) {
var M = [2,1];
var result = numbers.split('').reverse().map(function(v, i) {
return parseInt(v)*multipliers[i % M.length];
}).reduce(function(a,b){return a+b});
return (10 - result % 10) % 10;
}
@moreirayokoyama
Copy link

Eu não sabia que o Map podia me enviar o índice da iteração... que loko.

Tb não conhecia o reduce.

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