Created
April 4, 2018 09:03
-
-
Save ProgramAlgo/6e878dce53665f1934d6c37cda8ef142 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
const arr = []; | |
function checkArr(val) { | |
console.log('checkval', val); | |
const i = arr.indexOf(val); | |
if (i !== -1) { | |
arr.splice(i, 1); | |
} else { | |
arr.push(val); | |
} | |
} | |
// test | |
console.log('begin', arr); | |
checkArr('1'); | |
checkArr('2'); | |
checkArr('3'); | |
checkArr('2'); | |
console.log('end', arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment