Thank you for posting this, as it has helped. It is doing what I need it to, however, I can't get a trigger to work with it because I keep getting the following error:
"TypeError: input.reduce is not a function"
Can anyone advise? Thanks in advance!