Created
February 20, 2019 13:54
-
-
Save OlivierJM/7b5765686af9d5aa3ff6259f4c1eea7b to your computer and use it in GitHub Desktop.
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 removeSymbol(number){ | |
// make sure we are getting a string | |
if (typeof number !== "string") throw new TypeError("Expected string"); | |
// check if the number has the + sign and remove it | |
if(number.includes("+")){ | |
return number.replace(/\+/gi, "") | |
} | |
return number | |
} | |
// using flat arrows | |
const removeSymbol = number => (number.includes("+") ? number.replace(/\+/gi, "") : number); | |
// usage for the above | |
removeSymbol("+260972342432") // would give us this "260972342432" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment