Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by TimT for Is it possible to use .contains() in a switch statement?

An alternative implementation might be this. Not much in it but reads better than switch(true)...

const href = window.location.href;const findTerm = (term) => {  if (href.includes(term)){    return href;  }};switch (href) {  case findTerm('google'):      searchWithGoogle();      break;  case findTerm('yahoo'):      searchWithYahoo();      break;  default:      console.log('No search engine found');};

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>