I have the following JavaScript on my site so that when certain specific searches are performed, the answer is hardcoded to a specific page:
function redirect() {
var input = document.getElementById('searchBox').value.toLowerCase();
switch (input) {
case 'rectangular':
window.location.replace('http://www.Example.com/Rectangular/');
break;
case 'elephant':
window.location.replace('http://www.Example.com/Elephants/');
break;
case 'coils':
window.location.replace('http://www.Example.com/Parts/');
break;
default: // No keyword detected: submit the normal search form.
return true;
break;
}
return false; // Don't let the form submit
}
I'm wondering whether the search statement in JavaScript is linear on the number of case statements or constant time? If linear, is there a better way to write this code so it is constant time regardless of the number of special cases I code?