Detect Data Type
EasyP3Coding
Implement detectType(value), an accurate version of typeof that returns a lower-case type name.
nullreturns"null"andundefinedreturns"undefined".- Functions return
"function". - Other primitives return their
typeofname:"number"(includingNaN),"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
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.