Last active
April 15, 2018 23:26
-
-
Save souporserious/228898fea73e283e2f0a5fb0440757ab 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
function shallowEqual(a, b) { | |
return JSON.stringify(a) === JSON.stringify(b) | |
} | |
function toggleValue(value, item) { | |
let previousValue = false | |
const newValue = value.reduce((values, value) => { | |
if (shallowEqual(item, value)) { | |
previousValue = true | |
return values | |
} else { | |
return [...values, value] | |
} | |
}, []) | |
if (!previousValue) { | |
newValue.push(item) | |
} | |
return newValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment