Created
June 18, 2021 09:58
-
-
Save bhaireshm/299bb885ad7f6b443e7917b82b715979 to your computer and use it in GitHub Desktop.
Add or delete an element from an array.
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
/** | |
* @param arr: Array | |
* @param ele: element to be added | |
* @param remEle: element to be deleted | |
*/ | |
function addDelEleFromArray(arr = [], ele = "", remEle = "") { | |
if (ele && !arr.some((a) => a == ele)) arr.push(ele); | |
if (remEle) return arr.filter((a) => a != remEle); | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment