How could I implement a function in javascript which would take a list of strings as input, and would output the "smallest" (loosely speaking) type that all those strings can be parsed to?
Examples:
Input: ["true", "false", "false"] => Output: "boolean".
Input: ["1", "4", "-9"] => Output: "int".
Input: ["1", "4.3", "-9"] => Output: "float" (or "double", doesn't matter).
Input: ["9/1/2016", "2016-9-1"] => Output: "DateTime".
Input: ["1", "4.3", "9/1/2016", "Nastassja Kinski"] => Output: "string".
Remarks:
- It's ok to label everything else (functions, objects, arrays) as "string".
- It's ok to label anything date-related as "DateTime", even if there is not time component present.
- It requires differentiation between int and float (that's why my ouputs are strings instead of native types such as Number).
- It doesn't need to be perfect; just something that roughly works (at I can refine if needed).
- The input arrays would have 100 elements each.
Thanks a lot!