Skip to content

Instantly share code, notes, and snippets.

@akhilome
Created August 17, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhilome/45b7009059fa8d6fb4506e107aeb75fc to your computer and use it in GitHub Desktop.
Save akhilome/45b7009059fa8d6fb4506e107aeb75fc to your computer and use it in GitHub Desktop.
Recursively remove punctuation from end of words in Javascript
function stripWords(word) {
if(/[a-z]/.test(word[word.length - 1])) {
return word;
} else {
return stripWords(word.substring(0, word.length - 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment