Skip to content

Instantly share code, notes, and snippets.

@OlivierJM
Last active February 20, 2019 13:58
Show Gist options
  • Select an option

  • Save OlivierJM/e853a6b6427a7c1669bc156fdd86f609 to your computer and use it in GitHub Desktop.

Select an option

Save OlivierJM/e853a6b6427a7c1669bc156fdd86f609 to your computer and use it in GitHub Desktop.
// zambian mobile numbers start with 09x in case the user typed it start with a 2
// then its a country code prefixed
// es6
const removePrefix = num => num[0] == 2 ? num.substring(3) : num[0] == 0 ? num.substring(1) : num;
// es5
function removePrefix(num){
if(num[0] == 2){ // check if it starts with a 2
return num.substring(3) // remove numbers up to index 2 of the value
} else if(num[0] == 0){ // check if the value starts with a zero
return num.substring(1) // remove the o
}
return num
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment