title: Converting a specific if/else if/else to switch
body: <p>I'm struggling a bit here, so I could use a bit of an outside opinion. I've had to quickly (and messily) write a function full of if/else statements to get something done, but now I have some more time to spend on it and I'd like to convert it to a switch. Been wracking my brains on this but I just can't seem to figure it out.</p>
  
  <pre><code>// This is just the function, this is fine as it is.
  var between = "...";
  var val = x.value.split("&amp;&amp;")
      val.forEach(function(y){
          application.output(y)
          if(y.search("{")!=-1.0) {
              y=y.substring(1,y.length)
          } else {
              if(y.search("}")!=-1.0){
              y=y.substring(0,y.length-1)
              }
          }
  
  // Below is what Im trying to build a switch out of
  if(y.search("!")!=-1.0) {
  
              if(y.search("%")!=-1.0) {
                  y=" NOT LIKE '"+y.substring(1,y.length)+"'"
              } else if(y.search("&gt;") !=-1.0) {
                  y=" !&gt; '"+y.substring(2,y.length)+"'"
              } else if(y.search("&lt;") !=-1.0) {
                  y=" !&lt; '"+y.substring(2,y.length)+"'"
              } else if(y.search("...")!=-1.0) {
                  // Use the index &amp; final index of between to slice the two values apart
                  y=" NOT BETWEEN '"+y.substring(1,y.indexOf(between))+"'"+" AND '"+y.substring(y.lastIndexOf(between)+3,y.length)+"'"
              } else {
                  y=" != '"+y.substring(1,y.length)+"'"
              }
          // If user is inputting operators   
          } else if (y.search("&gt;") !=-1.0) {
              y = " &gt; '"+y.substring(1,y.length)+"'"
          } else if (y.search("&lt;") !=-1.0) {
              y = " &lt; '"+y.substring(1,y.length)+"'"
          } else if (y.search("...")!=-1.0) {
              y=" BETWEEN '"+y.substring(1,y.indexOf(between))+"'"+" AND '"+y.substring(y.lastIndexOf(between)+5,y.length)+"'"
          } else {
              if(y.search("%")!=-1.0) {
                  y=" LIKE '"+y+"'"
              } else {
                  y=" = '"+y+"'"
              }
          }
          y=" and "+x.name.toString()+" "+y
          sql+=y
  </code></pre>
  
  <p>The function takes operators passed in via user input and builds an SQL query out of it. Not even sure if it's possible to transform it into a switch, but there may well be a way.</p>