Last active
July 26, 2017 08:24
-
-
Save aeinbu/8cea7a926beecb0bf3c43043f16877a9 to your computer and use it in GitHub Desktop.
This file contains 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
// traditional version | |
function toggleValueInArray1(val, arr) { | |
var ix = arr.indexOf(val); | |
if(ix === -1){ | |
// add to array | |
arr.push(val); | |
} | |
else | |
{ | |
// remove from array | |
arr.splice(ix, 1); | |
} | |
} | |
// functional version | |
let toggleValueInArray2 = arr => val => { | |
var ix = arr.indexOf(val); | |
if(ix === -1){ | |
// add to array | |
arr.push(val); | |
} | |
else | |
{ | |
// remove from array | |
arr.splice(ix, 1); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage of the traditional version
Usage of the fp version