I don't know if this is a question for here or a more programming forum. But since it's in Node-Red I thought I'd start here.
I have a function that started off checking for spaces in a value for a specific object in the payload and replacing them with an '_'. It works wonderfully (cause I stole ah, borrowed the code ) so I've repeated it a few times for some other values that also needed to be massage for the flow to work.
Now I need to add about 20 more. I know just enough about programming to be dangerous, but I do know that poor coding can impact performance and I'm wondering if there is a better, more efficient way to handle the replacing I need to do.
I'm taking a spoken input from rhasspy to set the thermostat to a specific temperature.
'Set the temperature to 21 degrees'.
Because of Phonetics, I've set the values (in Rhasspy) from Ten to Thirty (words not numeric) in half degree incriments. I've sorted out how to deal with 'point five' or 'and a half'.
Is there a better way to handle this statement without repeating it for each value?
In this example 'twenty' can be any degree value between Ten and Thirty, and '20' would be the corresponding numerical value of the written degree value.
if (msg.slots.degrees) {
msg.slots.degrees = msg.slots.degrees.replace("twenty", "20");
}