Skip to content

Instantly share code, notes, and snippets.

@suissa
suissa / cpf.refatorado.suissa.js
Last active March 17, 2018 12:30
Validação de CPF, para refatorar, de um aluno.
const times = ( i ) => ( vlr ) => i * vlr
const mod11 = ( num ) => num % 11
const times10 = ( num ) => times( 10 )( num )
const isEqual = ( a ) => ( b ) => b === a
const isNotEqual = ( a ) => ( b ) => !( isEqual( a )( b ) )
const getDigit = ( cpf ) => cpf.charAt( 9 ) + cpf.charAt( 10 )
const getGeneratedDigit = ( sum1, sum2 ) => times10( sum1 ) + sum2
const generateStringSequence = ( tam ) => ( num ) => `${num}`.repeat( tam )
const gerenateArray = ( length ) => Array.from( { length }, ( v, k ) => k )