Skip to content

Instantly share code, notes, and snippets.

@souporserious
Last active April 15, 2018 23:26
Show Gist options
  • Save souporserious/228898fea73e283e2f0a5fb0440757ab to your computer and use it in GitHub Desktop.
Save souporserious/228898fea73e283e2f0a5fb0440757ab to your computer and use it in GitHub Desktop.
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