Created
February 12, 2019 02:51
-
-
Save stevenbeales/d9a26ad587ba7b5cd99f11c9e24512b3 to your computer and use it in GitHub Desktop.
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
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean); |
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
words('I love javaScript!!'); // ["I", "love", "javaScript"] | |
words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"] | |
Converts a given string into an array of words. | |
Use String.prototype.split() with a supplied pattern (defaults to non-alpha as a regexp) to convert to an array of strings. Use Array.prototype.filter() to remove any empty strings. Omit the second argument to use the default regexp. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment