Skip to content
Onsite

Detect Data Type

EasyP3Coding

Implement detectType(value), an accurate version of typeof that returns a lower-case type name.

  • null returns "null" and undefined returns "undefined".
  • Functions return "function".
  • Other primitives return their typeof name: "number" (including NaN), "string", "boolean", "symbol", "bigint".
  • Arrays return "array"; other built-in objects return their lower-case built-in name, for example "date", "map", "set", "regexp", "promise", "error".
  • Plain objects and instances of user-defined classes return "object".

Example 1

Input
detectType([]), detectType(null), detectType(new Map())
Output
'array', 'null', 'map'

Constraints

  • value can be of any type.

Hints

Run checks the 3 visible tests, Submit all 8.