Created
December 26, 2016 18:31
-
-
Save JoshuaKGoldberg/8d2485073ba40d3fd0c99afb6786f418 to your computer and use it in GitHub Desktop.
Multiply all numbers in a string by a constant
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
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