JSFiddle - React, Tailwind, and code Playground
JavaScript
var result = ['/test/bah.js', 'foo.js'].reduce(function (previousValue, currentValue, index) {
if ((index === 0) || ((/\/dist\//i).test(currentValue)) || ((/\/test\//i).test(previousValue)) ) {
return currentValue;
}
return previousValue;
});
console.dir(result);