-
-
Save juanplopes/2003306 to your computer and use it in GitHub Desktop.
Mod 10 (declarative fashion)
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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eu não sabia que o Map podia me enviar o índice da iteração... que loko.
Tb não conhecia o reduce.