Reuse functions across several actions & scripts?

I have a few functions like this:

function filterNegaMatch (myArray, matchCriteria) {
var v_regexp = new RegExp(matchCriteria,"gi")
return myArray.filter(function(candidateLine) {
	return !(candidateLine.match(v_regexp));
});
}

I use it already in that one action, but if I am going on to build other actions, should I keep pasting separate copies or is there a way to reference this code from another script?

There are several ways, most common ones…

  1. Place your reusable functions in a separate action, and use the Include Action step to include that action in others.
  2. Save your reusable JS in a file in /iCloud Drive/Drafts/Library/Scripts and use the require function to load those scripts. Docs.