The following js script receives the variable "datum" from an external source and evaluates what type of data it is. Please, PLEASE tell me there's a more elegant way to write that particular code:
// declare global variable
var datumEval
// is-datum-a-string function
var stringCheck = new function() {
if (isNaN(datum) {
datumEval = "string";
}
else {
return;
}
};
// is-datum-a-bool function
var boolCheck = new function() {
if (datum === true || datum === false) {
datumEval = "bool";
}
else {
return;
}
};
// is-datum-negative function
var negCheck = new function() {
if (abs(datum) === datum) {
datumEval = "positive";
}
else {
datumEval = "negative";
}
};
// is-datum-integer-or-float function
var floatCheck = new function() {
if (Math.floor(datum) === datum) {
datumEval += " integer";
}
else {
datumEval += " float";
}
};
// main code block
if (stringCheck(datum)) {
return datumEval;
}
else if (boolCheck(datum)) {
return datumEval;
}
else {
negCheck(datum);
floatCheck(datum);
return datumEval;
}