Using a temporary array to check for equality instead of multiple if statements

By Steve Claridge on 2014-03-15.

If you have multiple if statements that are checking for equality, something like:

def kingofqueens1(name) {
  name = name.toLowerCase()
  return (name == "doug" || name == "carrie" || name == "deac" || name == "arthur")

Then you could rewrite it to use a temporary array and call its contains() function for slightly shorter and cleaner syntax:

def kingofqueens2(name) {
  return ["doug","carrie","deac","arthur"].contains(name.toLowerCase())