Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@moreirayokoyama moreirayokoyama commented Mar 9, 2012

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