Last active
March 7, 2018 22:39
-
-
Save itacirgabral/ce0f7922f14e23aa64eaec1fdfe81b6f to your computer and use it in GitHub Desktop.
This file contains 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
const hadChanged = list => obj => Object.keys(list) | |
.filter(k => obj[k] !== list[k]) | |
.reduce((a, b) => { | |
list[b] = obj[b] | |
return a || !!b | |
}, false) | |
export default hadChanged | |
/* | |
var list = { a: 'a', b: 'b'} | |
var obj = { a: 'a', b: 'b', c: 'c'} | |
var checkAB = hadChanged(list) | |
checkAB(obj) | |
obj.c = 'defg' | |
checkAB(obj) | |
obj.a = 'u' | |
checkAB(obj) | |
checkAB(obj) | |
checkAB({}) | |
checkAB({}) | |
var checkVoid = hadChanged({}) | |
checkVoid(obj) | |
checkVoid(obj) | |
checkVoid({}) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment