Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Last active March 7, 2018 22:39
Show Gist options
  • Save itacirgabral/ce0f7922f14e23aa64eaec1fdfe81b6f to your computer and use it in GitHub Desktop.
Save itacirgabral/ce0f7922f14e23aa64eaec1fdfe81b6f to your computer and use it in GitHub Desktop.
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