Skip to content

Instantly share code, notes, and snippets.

@JoshuaKGoldberg
Created December 26, 2016 18:31
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 JoshuaKGoldberg/8d2485073ba40d3fd0c99afb6786f418 to your computer and use it in GitHub Desktop.
Save JoshuaKGoldberg/8d2485073ba40d3fd0c99afb6786f418 to your computer and use it in GitHub Desktop.
Multiply all numbers in a string by a constant
function multiplyNumbersInString(source, constant) {
return source.replace(/((\d\.\d)|(\.\d)|\d)+/g, digit => digit * constant);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment