implementing a typeswitch in javascript
//type switches in JS
function typeSwitch(elem){
switch(typeof elem){
case 'number':
return 0;
break;
case 'string':
return 1;
break;
case 'boolean':
return 2;
break;
default: return 3;
}
}
/* typeSwitch(8)
=> 0
typeSwitch('8')
=> 1
typeSwitch(false)
=> 2
typeSwitch('false')
=> 1
typeSwitch([])
=> 3*/