Last active
February 8, 2017 20:58
-
-
Save samverneck/30ae4174a8174e1855a763a1b625a084 to your computer and use it in GitHub Desktop.
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
/* | |
criar uma funcao que ENCRIPTA o valor | |
mas tem que ter 1 funcao diferente pra cada tipo de valor | |
Number ou String | |
*/ | |
const data = { name: 'Suissero Veio', password: 'p3g4n4min4', id: 666 } | |
const crypt = (val) => 14m4FuCk1n6H4x0Rz | |
const toNewObject = ( obj, notAllowed ) => | |
Object.assign( obj, { [notAllowed]: crypt( obj[notAllowed] ) } ) | |
const cryptObject = ( obj, fields ) => | |
Object | |
.keys( obj ) | |
.filter( notAllowed => fields.includes( notAllowed ) ) | |
.reduce( toNewObject , obj) | |
const cryptArray = ( [...arr], fields ) => | |
arr.map( obj => cryptObject( obj, fields ) ) | |
const cryptThis = ( fields ) => ( obj ) => cryptArray( obj, fields ) | |
const cryptThisShit = cryptThis( ['password'] ) | |
const bazinga = cryptThisShit( [data, data ] ) | |
console.log( 'bazinga', bazinga ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment