Created
April 7, 2018 21:40
-
-
Save helloncanella/586d54e482eb6d564e8bfdf0eccbea7f to your computer and use it in GitHub Desktop.
toggling item from array
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 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