Skip to content

Instantly share code, notes, and snippets.

@queviva
Last active February 5, 2022 21:18
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 queviva/5e0ab15d96dcbf55bbb51e245c522b9a to your computer and use it in GitHub Desktop.
Save queviva/5e0ab15d96dcbf55bbb51e245c522b9a to your computer and use it in GitHub Desktop.
converts a string into an array of numbers
const toNumArray = s => s.match(/[\d\.-]+/g).map(p=>Number(p));
@queviva
Copy link
Author

queviva commented Feb 1, 2022

uses a really quick and highly functional match to convert anything that resembles a number into an actual number

toNumArray('hsla(270,80%,40.25%,0.7)') //[270, 80, 40.25, 0.7]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment