I am just trying to understand javascript as I am a bit new to it and its such a power-full language.
I wanted to know how to re-arrange words and numbers in a string so some words can always be in the front. So in this case the number and measurement will always be in front of the value.
For example the desired output from input:
Function input: Wood Plank 1 cm
Function output: 1 cm Wood Plank
Function input: Lawn Mower 1
Function output: 1 Lawn Mower
Function input: Tape Measure
Function output: Tape Measure
I have this regex that I made which works but I need to know how to apply it
const unitCapturingRegX = (/^(?<amount>¼|½|¾|\d+\/\d+|\d+)\s*(?<value>.*)$/);
I have got some measurements below:
const measures = [
"cm", "m", "kg", "kgs", "kilogram", "kilograms", "l", "liter" ,"tbs","meter", "inch",
];
This is my input Values:
const inputVal = [
'Tape 1/2 cm',
'1kg cement',
'3 l water',
'carbon fibre ½ inch'
]
Is this a possible thing to do , please can someone help me!!!
Add the units to the end of the regualr expression
And generating it from the array