Let a = "cat AND mouse AND hen OR pig AND cow OR horse"
Expected output ="((cat AND mouse AND hen) OR (pig AND cow) OR horse)"
All the consecutive AND should be inside a bracket.
var a = "cat AND mouse AND hen OR pig AND cow OR horse"
var orSplits =
a = "("+a.replace(/ OR /g, ") OR (")+")";
console.log(a)