Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Created April 7, 2018 21:40
Show Gist options
  • Select an option

  • Save helloncanella/586d54e482eb6d564e8bfdf0eccbea7f to your computer and use it in GitHub Desktop.

Select an option

Save helloncanella/586d54e482eb6d564e8bfdf0eccbea7f to your computer and use it in GitHub Desktop.
toggling item from array
function toggler(collection, item) {
var clone = [...collection]
const idx = _.indexOf(clone, item);
if(idx !== -1) {
clone.splice(idx, 1);
} else {
clone.push(item);
}
return clone
}
var model = [1, 2, 3];
var toggle = _.partial(toggler, model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment