Skip to content

Instantly share code, notes, and snippets.

@OlivierJM
Created February 20, 2019 13:54
Show Gist options
  • Save OlivierJM/7b5765686af9d5aa3ff6259f4c1eea7b to your computer and use it in GitHub Desktop.
Save OlivierJM/7b5765686af9d5aa3ff6259f4c1eea7b to your computer and use it in GitHub Desktop.
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