Programming Language Identification in JS
Instead of ||, you could stuff the patterns in an array and use array.some(). If one of the patterns match the string, it will return immediately with true and skipping the rest of the array.

const patterns = []
patterns.push(pattern1)
patterns.push(pattern2)
patterns.push(pattern3)
return patterns.some(p =&gt; string.match(p))


Taking it further, you can use a key-value pair of language name and patterns. Then use Object.keys and array.find to find which key has the set of patterns that match the string. For the sake of brevity, variable names are shortened.

const l = {
  java: [/* array of java patterns */],
  python: [/* array of python patterns */],
  c: [/* array of c patterns */]
}

// "For each language in languages, find the language that contains a
// pattern that matches the string"
const language = Object.keys(l).find(k =&gt; l[k].some(p =&gt; s.match(p)))


Also note that some languages have common syntaxes. If you want to go this route, you'll have to find syntax that's unique to the language or risk mistaking one language for another. For instance, True may be a Python boolean... or a variable name in Java. The same with class, is it a Python class or Java class. What if I defined a string in Java that's valid Python?